Make Object Properties Private and public

Make Object Properties Private and public
0

#1

Tell us what’s happening:
I’ve set the variable ‘gear’ as a private property and the rest are public properties. I’ve set this.retrieveGear function so that I can return the result of gear. I don’t understand what I’m doing wrong.

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 = 0;
  
  this.getGear = function() {
    gear++;
  };
  
  this.setGear = function() {
    gear--;
  };
  
  this.retrieveGear = 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

setGear should set the gear to the value that is passed to the function. getGear should return the value of gear.


#3

I’ve done that, now I have:
var Bike = function() {

// Only change code below this line.
var gear = 4;

this.getGear = function(change) {
gear += change;
};

this.setGear = function() {
return gear;
};

};


#4

getGear should return the value of gear.
setGear should set the value of gear (not add X amount to it).


#5

Then how else should I get the value of gear?


#6

Currently setGear (instead of getGear) returns the value of gear.