What is wrong with this code. It seems I am getting an error that the timer is not defined.
var counter = setInterval("timer()",1000); function timer(){ count = count-1; if(count <=0){ clearInterval(counter); return; } document.getElementById("timer").innerHTML = count + " sec"; }
setInterval
Your function is a local variable that does not exist if setTimeouteval is a string in the global scope.
setTimeout
Instead, pass this function to setInterval:
var counter = setInterval(timer, 1000);