[Vuejs]-VueJS setTimeout is not setting the time out

2👍

Why are you even creating an array if you do not need to reference the timeouts later? You can just “manually” space-out timers by 1 second

// mocking code:
var challenge = [0, 1, 2, 3];

for (let i = 0; i < 2 * challenge.length; i++) {
  setTimeout(function() {
    play(Math.floor(i / 2), i % 2 === 0);
  }, 1000 * i);
}

function play(audioIndex, playAction) {
  if (playAction) {
    console.log("playing audio: " + audioIndex);
  } else {
    console.log("stopping audio: " + audioIndex);
  }
}

Leave a comment