Unable to update Inventory Class | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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