The code:
for(var a=0;a<=60;a++){
setTimeout(function(){
document.getElementById("a").innerHTML=a;
},1000);
}
It displays 61 with no delay at all. I can not see any reason why it would do that...
The code:
for(var a=0;a<=60;a++){
setTimeout(function(){
document.getElementById("a").innerHTML=a;
},1000);
}
It displays 61 with no delay at all. I can not see any reason why it would do that...
What you are trying to achieve is clearly an implementation of setInterval.
var a = 0;
function displayIncreament() {
if (a <= 60) {
document.getElementById("a").innerHTML = a;
a++;
} else {
clearInterval(IncreamentInterval)
}
}
var IncreamentInterval = setInterval(displayIncreament, 1000)
<span id="a"></span>