+ 1

What exactly does this do?

So I got this code from somebody not too long ago. I was looking through it, and noticed that the js contained no click event anywhere. So I checked the button and found this. No idea what it actually does. Also run is a var set to "TRUE" <button onclick="run =!run">Toggle</button> https://code.sololearn.com/W3Bt5Niq823X/?ref=app

17th Jun 2018, 5:33 AM
Daniel Cooper
Daniel Cooper - avatar
2 ответов
+ 7
When we click on the button, it toggles the value of the variable 'run' (if it's true it makes it false and if false it makes it true) and next, function Count() { if(run) document.getElementById("output").innerHTML = ++i; setTimeout("Count()", 100); } if(run) { //code here } If the value of run is true it executes the code and if false , it does nothing
17th Jun 2018, 5:41 AM
Nikhil
Nikhil - avatar
+ 2
js runs independently so no onclick event required when button is clicked, "run" is set to false and line no.9 in js is not executed and counter stops on second click, "run" is set to true and line no. 9 is executed, incrementing the counter
17th Jun 2018, 5:46 AM
‎ ‏‏‎Anonymous Guy