Skip to content
Advertisement

JavaScript countdown timer counting past zero

This might be a really simple thing to ask but I’ve got a JavaScript countdown timer, but I can’t stop it from counting past 0:00. Instead of stopping at this point, it will continue to -1:59 etc.

I’d also like it to play a beeping sound (which can be found here) when the timer reaches zero.

This is the code I’ve got so far:

JavaScript

Any help on this would be appreciated.

Advertisement

Answer

To stop the counter when it reaches zero you have to stop calling the startTimer() function. In the following snippet I have implemented a check to do exactly that.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement