Make Unique Objects by Passing Parameters to our Constructor...how can I improve this?

Make Unique Objects by Passing Parameters to our Constructor...how can I improve this?
0

#1

Hi,

There is something wrong with this code. How could I improve this?


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

//Try it out here
var myCar = function (wheels, seats, engines) {
  this.wheels = wheels;
  this.seats = seats;
  this.engines = engines;
};

var myCar = new Car (3, 8, 2);

Edit: it gives these error messages:

Calling new Car(3,1,2) should produce an object with a wheels property of 3, a seats property of 1, and an engines property of 2.

Calling new Car(4,4,2) should produce an object with a wheels property of 4, a seats property of 4, and an engines property of 2.

Calling new Car(2,6,3) should produce an object with a wheels property of 2, a seats property of 6, and an engines property of 3.


#2

You haven’t changed Car constructor. It’ll always return 4 wheels, 5 seats and 1 engines.


#3

Is that your actual code?

Because if so … you didn’t do what was requested. You almost did. The instructions were to change the Car constructor (see the comment at the top).

You made a new constructor function called myCar. The automated tests are still testing against Car and returning incorrect values.

Delete your myCar function and modify the Car function and give it another go …