i want to show numbers one by one after a second, but below coding shows the whole numbers together.
function showVal(){
for(i=0; i<5; i++)
{
var showingVal= document.write("the number is "+i);
document.write("<br />");
}
}
setInterval('showVal()',1000);
It’s better to use
setTimeoutinstead.Demo: http://jsbin.com/avunif
It’s better than
setIntervalbecause after you printed 5 numbers, your tick handler won’t be called. Efficiency. Plus no global variables. 🙂Or you can
clearIntervalinstead.