What's wrong with my code? I can't get the timer to stop at 0. It keeps going down to negative numbers. I have my clearInterval set, why isn't the timer stopping?
var seconds = 30;
$("#timer").on("click", run);
$("#timer").on("click", show);
var timer;
function run() {
clearInterval(timer);
timer = setInterval(decrement, 1000);
}
function decrement() {
seconds--;
$("#timer").html("<h2>" +"Time Remaining: " + seconds + "</h2>");
}
// Stop function
function stop() {
clearInterval(timer);
}
// When seconds hit zero
if (seconds === 0) {
stop();
alert("Time's Up!");
}