Simon help please!

Need a little help with Simon before I move on. So far it only plays a sequence and you have to copy but it wont keep track of what colors you press, only the amount of presses. The issue is the first time I play when the page loads it works, but if I restart or power off and back on again it will always skip the second turn. I have the console logging the turn count and you will see it in action. I cannot for the life of me figure out why. Please help!

Of course there are others problems but at the moment i’ve found this part:

  //run computer sequence
  function runSeq() {
    if (!power)
    $("#display").html(index + 1);
    var $next = $(seq[index]);
    timeout = setTimeout(function() {
      if (index >= turn) {
        playerTurn = true;
        player = [];
      } else {
        setTimeout(runSeq, 200);
    }, 800);

Especially in:

setTimeout(runSeq, 200);

You make runSeq recursive, and every time init a new process, and clearTimeout () need a timeoutId not a function. WindowTimers.clearTimeout

1 Like