Make Object Properties Private 12/5/2017

Make Object Properties Private 12/5/2017
0

#1

Tell us what’s happening:
Not sure why i get a green check for “myBike.getGear() should return 4 after calling myBike.setGear(4).” but the i dont for the 2 below it using my code.

Your code so far

var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.
  var gear = 1;
  this.setGear = function(change){
    gear *= change;
  };
  this.getGear = function(){
    return gear;
  };
};

var myCar = new Car();

var myBike = new Bike();

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36.

Link to the challenge:


#2

gear *= change;
Are you supposed to be multiplying the old gear by the change value?


#3

it doesn’t say… here’s what it says:

Now try it yourself! Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.

And here’s what they expect to see:

The method getGear of myBike should be accessible outside the object.
The method setGear of myBike should be accessible outside the object.
myBike.gear should remain undefined.
myBike.getGear() should return 4 after calling myBike.setGear(4).
myBike.getGear() should return 3 after calling myBike.setGear(3).
myBike.getGear() should return 1 after calling myBike.setGear(1).


#4

Let me rephrase:
Why are you multiplying the gear by the change value?