0

I need then x=0 it stoped, help pls and sry for bad english

var x = prompt("Произвести отсчет от "); var z = 0; do { ot(); } while(x>0); function ot() { document.write(x); x--; } setInterval(ot,1000);

8th May 2017, 7:34 AM
qwqw
1 Respuesta
+ 4
no need for a do while loop here setInterval calls ot every 1000 ms (1 second) the only thing you do need to do is use the id that setInterval returns so you can use it for clearInterval once the condition is met var x = prompt("Произвести отсчет от "); var z = 0; interval=null; function ot() { document.write(x); x--; if(x <= 0){ // if x reached 0, stop the interval calls clearInterval(interval); } } interval = setInterval(ot,1000); // calls ot() every 1 second
8th May 2017, 7:50 AM
Burey
Burey - avatar