Here is a simple code snippet where I'm experimenting with starting, stopping, and resetting a JavaScript timer.
The goal is to have a timer running on a page that sends a message once it reaches the end of its countdown before restarting. The stop button should halt the timer indefinitely.
The code in the provided fiddle achieves this functionality, but I am unsure if I am approaching it correctly. Is using setTimeout
the most effective way to create such a timer, or would setInterval
be better?
Additionally, my current reset function looks like this:
var onReset = function() {
clearTimeout(timerHandle);
onStart();
};
Is there a more elegant method to reset a timer in JavaScript?
Any insights are appreciated!