+ 2
Unable to update Inventory Class
Hello, I have a small code which tries to create a “bag” object, and update the “size” property, but it does not work. The result should be 15, but instead it shows 6. Can anyone give some hints what did I do wrong?? Regards, Ben class Inventory{ constructor(size){ this.size = size; } increase(size){ this.size = size + 1; } } var bag = new Inventory(10);//create bag object with 10 bags console.log(bag.size); //print initial bag size bag.increase(5); //increase bag size console.log(bag.size); //print bag size https://code.sololearn.com/WlFsqD8Nh95n/?ref=app
2 ответов
+ 1
Try
this.size += size;
or
this.size = size + this.size;
+ 2
@Calvin thank you!