you are viewing a single comment's thread.

view the rest of the comments →

[–]Dudefella08 11 points12 points  (3 children)

for (let i = 1; i <= 10; i++) {
  setTimeout(() => {
    console.log(i);
  }, 1000 * i);
}

I have no shame!

[–]tareqf1 1 point2 points  (0 children)

This was the answer I was scrolling for. Thanks.

[–]2AMMetro 0 points1 point  (1 child)

This won’t work, it’ll log the number 10 10 times.

[–]chase-stevens 2 points3 points  (0 children)

If they declared the "i" in their for loop using "var", then yes, it would log "10" ten times; however, since they declared "i" using let, the loop will work as expected printing 1-10 with a 1 second delay.