Make Object Properties Private. Now What, Help!

Tell us what’s happening:

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 myCar = new Car();

var myBike = new Bike();
myBike.getGear = function() {};
myBike.setGear = function() {
  
 };

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6.

Link to the challenge:
https://www.freecodecamp.org/challenges/make-object-properties-private

Have a look here [ w3school].
You’re almost there but you’re missing the point of the challenge imho ^^
Have a look there and then look back at your code, i think it will become clear! :slight_smile:

1 Like