Adding in Js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Adding in Js

I want to do in web something like if you press a button it will add 1 to the var in js but its stuck in only 1. Do you know the clickers? when you press that button It always add 1? To give you an idea. Thanks for reading.

23rd Mar 2018, 9:12 PM
blackndBlue
blackndBlue - avatar
3 Answers
+ 2
Hi Goola sounds like you are calling a function that is initializing the variable to zero on each call. You need to use a glabal variable. ( not good practice) or use a Closure.
23rd Mar 2018, 9:22 PM
Mike Choy
Mike Choy - avatar
+ 4
umm ok I will try
23rd Mar 2018, 9:23 PM
blackndBlue
blackndBlue - avatar
+ 2
1. make a button 2. add an eventlistener to the button 3. add a function to the eventlistener 4. declare the function 5. push the button :)
24th Mar 2018, 2:58 AM
wenz
wenz - avatar