Ask coding questions

← Back to all posts
EmmaGao8 (33)

I have a value var x = "2". How can I increment x each second so that one second from when I defined x, x will equal to 3?

Answered by GameDev46 (213) [earned 5 cycles]
View Answer
GameDev46 (213)

You can use javascripts setInterval method!

Simply use the line of code:

var tick = setInterval(someFunction, 1000);

Where someFunction is your function to change the cookies by 1 and the number is how many milliseconds do you want to wait before calling it again. So the someFunction function will be called every second!