What is wrong with this code I seem to be geting an error that 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";
}
Don’t pass a string to
setInterval.Your function is a local variable, which doesn’t exist when
setTimeouteval’s the string in the global scope.Instead, pass the function itself to
setInterval: