Make Object Properties Private help

Make Object Properties Private help
0

#1

Hello, if someone could help me with this task. Dont know what I’m missing…

var Bike = function() {

var gear = 0;

this.setGear = function (i) {
gear += i;
};

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


#2

Hi,

In your setGear method you’re adding i to the gear total each time… I think this would mean that your gear numbers will keep incrementing. What you want is for ‘gear = i’.

Cheers,
Tim


#3

gear += i; this is same as gear = gear + i is that the desired effect ?


#4

‘gear = i’ solved the problem…