What is the simplest way to increase a variable by 1 every second?
var counter = 0;
setInterval(function () {
++counter;
}, 1000);
Additionally, if you ever need to turn it off again, this makes that possible:
var counter = 0;
var myInterval = setInterval(function () {
++counter;
}, 1000);
// to stop the counter
clearInterval(myInterval);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With