What’s wrong with this code? Why myBike.setGear() is the the only statement which does not work ? I’m getting a TypeError.
Thank you for your explanations.
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.setGear = function(x){
gear = x;
};
this.getGear = function(){
return gear;
};
};
myBike.setGear(4);
myBike.setGear(3);
myBike.setGear(1);
var myCar = new Car();
var myBike = new Bike();