I am attempting to display a countdown timer that starts at 20 minutes in the format (00:20:00) using setInterval. Once the countdown is finished, it should display as (00:00:00), but I am having trouble achieving this.
<body onload = "onloadFunc();">
<span id="minute"></span> <span id="second"></span>
<script type="text/javascript">
var interval;
function onloadFunc(){
secondDown();
interval = setInterval(secondDown, 1000);
}
var countsec = 60;
function secondDown(){
document.getElementById("second").innerHTML = countsec;
countsec--;
if(countsec == -1){
minuteDown();
interval = setInterval(minuteDown,60000);
countsec = 60
}
}
var countmin = 20;
function minuteDown()
{
document.getElementById("minute").innerHTML = countmin;
countmin--;
if(countmin == -1)
{
clearInterval(interval);
}
}
</script>
</body>