Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
188
rated 0 times [  194] [ 6]  / answers: 1 / hits: 30108  / 14 Years ago, tue, june 15, 2010, 12:00:00

What is the simplest way to increase a variable by 1 every second?


More From » jquery

 Answers
22
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);

[#96484] Sunday, June 13, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Mon, Jun 22, 20, 00:00, 4 Years ago
;