Make Instances of Objects with a Constructor Function (solved)

This is what I came up with. It passed but there were yellow triangles. Check it out.

var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};

// Only change code below this line.

var myCar = new function() {
this.wheels = 4;
this.nickname = “This is Sally.”;

};

Here is another example for understanding the exercise>

var Person = function(){
	this.name;
    this.age;
    this.high;
    this.color;
}

var employee = new Person();
employee.name = "Sousa Gaspar";
alert(employee.name)
2 Likes

Hi, I write these code for the challenge,

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};

// Only change code below this line.

var myCar = new Car();
myCar.nickName = "This is Rose";

The playground give this alert, “The property nickname of myCar should be a string.”, what am I doing wrong?

Thank’s

Hi,

Maybe it’s a cheat but I did this…

var myCar = new Car(); {
this.wheels = 4;
}

myCar.nickname = “ute”;

and it worked…

Hi campers!

Sincerely I dont know what is wrong with my code in this exercise. Is weird :neutral_face:, probably the solution is very simple but I dont see the problem.

Thanks you

posiblebug

nickname and nickName are two different properties.

The challenge asks you to use Car() as a constructor for myCar (see @sgenio’s post above for an example of using a constructor). What you’ve done is created a new constructor called myCar. A constructor is a function used to create objects, and the properties set with the this keyword within the constructor aren’t properties of the constructor itself; instead, they become properties of objects created using the constructor. To create objects using a constructor, you use the new keyword.

1 Like

// Only change code below this line.

var myCar = new car();
myCar.nickname = “pretty car”;

here’s what i came up what, still trying to figure out what’s wrong with my code please help

var myCar = new car(); tries to call constructor function car() instead of Car()

var myCar = new Car();

myCar.nickname = “Ravy”;

At first I was trying this.nickname = “Ravy”; …but I guess it wants myCar.nickname = “Ravy”;

1 Like

Just solved this one, basically just run the code and don’t overthink it.

At the top it shows you var myCar = new Car();

Then give it a nickname, not nickName

That solution worked for me.

This is what work for me.
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};

// Only change code below this line.
var myCar = new Car();{
myCar.wheels = 4;
myCar.nickname = “vboot”;
};

var myCar = new Car();

myCar.nickname = “Toyota”;

This work for me