+ 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

21st Jul 2019, 3:19 AM
Ben
2 ответов
+ 1
Try this.size += size; or this.size = size + this.size;
21st Jul 2019, 3:32 AM
Calviղ
Calviղ - avatar
+ 2
@Calvin thank you!
22nd Jul 2019, 1:16 AM
Ben