JS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

JS

How to make a button that can add value? Like when I click the button I got 10, then if I click the button again I got 20, then 30 40...

11th Oct 2020, 4:07 AM
Lyhour Chhay
Lyhour Chhay - avatar
1 Answer
0
Create a variable, initialized by 0 (zero). Let's call it <num>. Create a function which adds 10 to <num> on each invocation. Either call that function by using the "onclick" attribute of the button, or add an event listener on "click" event for the button as the DOM is completely loaded. I see you have finished HTML course and got the certificate. I suggest you to review the course, especially on DOM related chapters.
11th Oct 2020, 5:10 AM
Ipang