+ 2
How do I increase the value of a variable when an object is clicked? (Javascript Question)
I've ran into another problem while creating a virtual pet game. I want to increase the value of hunger when the leaf is clicked and print the value of hunger. What did I do wrong? HTML: <img onclick="increase()" src="https://www.vectorportal.com/img_novi/beautiful-leaf-icon.jpg" class="leaf"> Javascript: function increase() { hunger++= document.getElementById("food").innerHTML=hunger; Here's the link to the code: https://code.sololearn.com/We4BFeQJk50E
2 Answers
+ 5
1. variable falls into functional scope at line 4.
2. typo at line 24
fix :
https://code.sololearn.com/Wd49hTq255zM/?ref=app
readings :
https://www.sololearn.com/post/45261/?ref=app
+ 2
thank you so much Gordon !!