i am having issues figuring this out. the instruction is as follows: We can also create private properties and private methods, which aren't accessible from outside the object.
To do this, we omit the word this from the property or method declaration.
See if you can keep myBike.speed and myBike.addUnit private, while making myBike.getSpeed publicly accessible.
here is the code:
var Car = function() {
this.gear = 1;
function addStyle(styleMe){
return 'The Current Gear Is: ' + styleMe;
}
this.getGear = function() {
return addStyle(this.gear);
};
};
var Bike = function() {
// Only change code below this line.
this.speed = 100; //how do i change this method to be private?
function addUnit(value) {
return value + "KM/H"; //and this method too.
}
getSpeed = function () {
return addUnit(speed); //this method is supposed to remain public.
};
};
// Only change code above this line.
var myCar = new Car();
var myBike = new Bike();
if(myBike.hasOwnProperty('getSpeed')){(function() {return JSON.stringify(myBike.getSpeed());})();};