Help with Simon Game please

Round 1 is great for both simon and player. In round 2 Simon keeps looping.

Can you help guide me in the right direction?

Here’s the pen:

Are the sounds defined (kiwisnd, for example)? And what does[0]; mean? Is the promise returned by play() viewed as an array?

I am still reviewing your code, but I did find some code which is doing absolutely nothing (see below).

     function playrMove() {
       curplayr = player;
       playr = [];
       console.log("Current Player is " + curplayr);
       return true;

OK, I am going to walk you through the important parts of what is happening with your code.

Click on Start and eventually the simonMove function runs. During the 1st iteration of the simonMove for loop, i=0 and round=1. After a setInterval is assigned to timing which eventually plays/highlights the first button. Then the clearInterval is called because n = 1 and round = 1.

Next, if I click on the same button which lit up, your solution gets stuck in the second setInterval created because it seems to never get cleared. I used console.log('inside setInterval # ’ + timing) just inside the callback function of setInterval, another console.log(‘getting ready to clear setInterval #’ + timing) before the clearInterval(timing) line and then put a console.log(‘assigned setInterval #’ + timing) on the line after the timing=setInterval(function() {…}); If you do the same, you will see the very first setInterval is cleared, but the 2nd one never does get cleared. I could be wrong about this, but without more testing, this is my conclusion.

The sounds are defined in the html settings below the header meta tags.

I am not sure why the [0] is there, I think I read that was the way to make it work. Apparently not since the first sound doesn’t happen when it should. I’ll remove those and see if it helps.

Thank you.

Thank you for catching that. the playr = []; should be playrseq = []

It was to be used to set the current player is the Player and the Player array is empty.

I have changed that.

Thank you,

The slight delay is because the sequence is randomizing 20 indexes before the Simon Move.

The first iteration should be round 1 at index 0.

The second iteration should be round 2 at index 0 - 1.

Your conclusion is correct. I can not find the way to clear the second setInterval and have the simon Sequence begin at index 0 through to the index of the current round.