I created a loop with the setTimeout function, and it comes to the problem after the second or third step, which it calls itself, because it starts to exit twice at that time. This is what my function looks like:
var value = 70, intervalID = null; function interval() { intervalID = setTimeout(countDown, 1000); } function countDown() { value--; if(value > 0) { clearTimeout(intervalID); interval(); } else { endInterval(); } } function endInterval() {
If I console the value of the variable to 69, 68, and after that it starts to decrease the value of the variable twice in one function call. I do not call the countDown () function anywhere, but from one place.
What could be the problem?
Edit: this code is working now.
source share