+ 1

Important question of JS

suppose i have a code to write counting 1 to 100 ,i write code like this for(i=1;i<=100;i++){console.log(i)} but this line write all counting at once when page loaded. but i have to write counting 1 by 1 not all at once;

9th Jan 2021, 9:59 PM
𝖆𝖙.đ–šđ•·
𝖆𝖙.đ–šđ•· - avatar
4 RĂ©ponses
+ 3
/*Okay, now I understood what you want. Unfortunatelly the above mentioned solution from Med Amine Fh do not works really. You can use this: */ let i = 1 const time = 1000 var Interval = setInterval(()=>{ console.log(i) i++ if(i>10) clearInterval(Interval) },time)
9th Jan 2021, 10:40 PM
JaScript
JaScript - avatar
+ 2
you need to set an interval , so you can run a piece of code every amount of time . try this one : let i = 1 const time = 1000 while(i <= 100){ var Interval = setInterval(()=>{ console.log(i) },time) i++ } clearInterval(Interval)
9th Jan 2021, 10:20 PM
Med Amine Fh
Med Amine Fh - avatar
+ 2
The output can be prepared and then printed: let sum = "" for(let i=1;i<=100;i++){ sum += i } console.log(sum)
9th Jan 2021, 10:22 PM
JaScript
JaScript - avatar
+ 2
setInterval() is perfect
9th Jan 2021, 10:26 PM
𝖆𝖙.đ–šđ•·
𝖆𝖙.đ–šđ•· - avatar