+ 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;
4 Respuestas
+ 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)
+ 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)
+ 2
The output can be prepared and then printed:
let sum = ""
for(let i=1;i<=100;i++){
sum += i
}
console.log(sum)
+ 2
setInterval() is perfect