I want to create a alert \"Hello\" which will show up after 10sec. I used setTimeout and it working fine. Now i would like to do counter(timer) which will show 10, 9, 8,7 ...
Simple variant:
var count=10; var counter=setInterval(timer, 1000); function timer() { count=count-1; if (count <= 0) { clearInterval(counter); alert("Finished!") return; } document.getElementById("timer").innerHTML=count + " secs"; // watch for spelling }
Working jsfiddle