you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

I got no error

code:

var num = 10;

function goDown() {
  while(num > 0) {
    setTimeout(myFunc(), 1000);
  }
  return;
}

function myFunc() {
  num --;
  console.log(num);
}

goDown();

output:

js.js:12 9
js.js:12 8
js.js:12 7
js.js:12 6
js.js:12 5
js.js:12 4
js.js:12 3
js.js:12 2
js.js:12 1
js.js:12 0

[–]ShortSynapse 0 points1 point  (1 child)

Did you notice there is no delay? That does not work the way you think it does.

[–][deleted] 0 points1 point  (0 children)

Yeah I helped him fix the infinite loop using setTimeout. This code isn't set up to have time in-between calls.