Hi all!
Could someone help me understand challenge 228 - Making Object Properties Private better? or recommend a site where I can go and understand this subject better?
I tested the code in codepen and the results are different when I do console.lor (myBike.getGear()), yet the challenge was “successful”.
Cheers!
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;
this.getGear = function () {
return gear;
};
this.setGear = function (num) {
gear = num;
};
};
var myCar = new Car();
var myBike = new Bike();