Problem with timer in JS
This timer is suppose to countdown to 3 to 0 and then 4 to 0 amd then 5 to 0. But after the first function runs, some numbers get skipped and its gets crazy. any suggestions? var t = 3; var T = document.getElementsByTagName('div'); function timer(){ T[0].innerHTML = 'Time: ' + t; function count(){ t--; T[0].innerHTML = 'Time: ' + t; if(t === 0){ timeagain(); } } var interval = setInterval(count, 1000); } function timeagain(){ t = 4; T[0].innerHTML = 'Time: ' + t; function count(){ t--; T[0].innerHTML = 'Time: ' + t; if(t === 0){ timeAgain(); } } var interval = setInterval(count,1000); } function timeAgain(){ t = 5; T[0].innerHTML = 'Time: ' + t; function count(){ t--; T[0].innerHTML = 'Time: ' + t; if(t === 0){ clearInterval(interval); } } var interval = setInterval(count,1000); }