Ask coding questions

← Back to all posts
setTimeout
DonoldJTrump

So I am trying to make a clicker game. I have a cookies per second variable, and I what to add it to the total cookies every second using setTimeout. For some reason, it will add it once,then stop.
Affected code:

Am I not doing the syntax right for setTimeout?

Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
DonoldJTrump
Comments
hotnewtop
SixBeeps

You need setInterval, not setTimeout. Timeout only executes once.

DonoldJTrump

@SixBeeps another stupid mistake

Coder100

the syntax expects a function, but not for you to call the function. If you did that, what happens is js calls the function and uses the value the function returns as the function in setTimeout, meaning nothing happens.

DonoldJTrump

@Coder100 Thanks, Coder100

Coder100

mark as correct answer? @DonoldJTrump

DonoldJTrump

@Coder100 six beeps answered my organs question, so I marked his post as the answer