In my quest to create a pomodoro clock, I decided to experiment with window.setInterval()
and its counterpart window.clearInterval
before delving into actual coding. However, I've encountered an issue with getting window.clearInterval()
to function as desired. Could someone please review my code snippet below and provide guidance on how to resolve this issue? Thank you in advance.
let startTime = 11;
let intervalID;
function countdown() {
startTime--;
$('h2').text(startTime);
}
if (startTime > 0) {
intervalID = setInterval(countdown, 1000);
} else {
clearInterval(intervalID);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h2></h2>