Simon Game Clear Set Interval Help

Hi, I am working on the Simon game project. I need to be able to turn the game on and off. When the game is off it needs to totally reset everything, and I have done that for the most part, but sometimes the lights continue to flash and won’t stop if I happen to hit stop in the middle of a flash on the second turn or so if there are more flashes after it. To replicate my issue turn the game on. hit start. copy the moves correctly and get to the third round. on the fourth round turn the game off in the middle of the flash on the third round. Then turn it back on and you will see. I have the same problem when I try to hit start in the middle of a flash. The start button needs to act as a reset button that will start a new game without turning the game off and back on. I added a console.log(game.pc) on line 101, and that is showing me that my setInterval() starts running continuously once the off button is hit and I don’t know what to do about this.

Start button code starts on line 137 Computer move code starts on line 91 On button line 66 Clear All line 38

Thanks for checking this out I really appreciate it.

I would guess it’s because you don’t clear setTimeout inside of your interval. It returns a timer identifier just like setInterval does. You could also check to see if the game is on before flashing each light.

I seemed to have gotten it by changing the moves variable in pcMove() to be set to a key value within the game object, and then clearing that when off is clicked. It works for when I turn it off, and when I hit the start button in the middle of a move, but the start button doesn’t work all the way still. If I click start again when a button is lit up, then it expects me to match 2 moves as opposed to one. You can see it in the console.