The following code should start and stop the timer, however the "stop" button is not working. "Play" works fine. it just wont stop
var countDown;
function countDownClock() {
var timeLeft = 5;
var text = document.getElementById("countDownTimer");
var countDown = setInterval(function() {
if (timeLeft == 0) {
clearInterval(countDown);
text.innerHTML = "finished!";
} else {
text.innerHTML = timeLeft;
}
timeLeft -= 1;
}, 1000);
}
<button onclick="reloadMaths()"><i class="fa fa-play"></i></button>
<button onclick="clearInterval(countDown);"><i class="fa fa-stop"></i></button>
do I need to show more JS?
originally i thought this post solved it as I did not have variable as a global variable -however, having made it global this solution is not working javascript countdown timer with start & stop buttons