Simon help please!

Simon help please!
0.0 0

#1

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!


#2

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

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

Especially in:

setTimeout(runSeq, 200);
clearTimeout(runSeq);

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