Hmmm… I think the question is a bit open ended, and without completely dissecting your code, this might be the best I can offer (keeping in mind there are likely several solutions to this problem):
- Create a function that randomly pushes a new color to an array every time a turn advances (computer’s moves), then display pattern.
- Create a click function that pushes the color of a users button push to a separate array, and within and at the end of that function, call another function that compares the two arrays to make sure they match. You can start with a base comparison of length - if the 2 arrays have different lengths, then the user did not press the right number of buttons and there is no reason to compare further. Then you can probably use a loop to compare the individual elements assuming the lengths match.
- If the patterns do match, trigger the function described in step 1 again to add a new color the the computer’s array, and display, then repeat.
To wait the right amount of time between a computer’s button pushes, you can use something like
setTimeout(), which you can also use in some fashion to “timeout” a users turn if they wait to long to push a button.
I hope this helps in some way, but the best approach I think is to always exhaustively use Read and Search to the best of your ability before asking (if you haven’t already). So instead of searching for the solution specifically for a Simon game, try to break down the individual problem you are having and see if you can find a solution for that, which might be apply to someone else’s problem in a completely different way… there are answers out there to just about everything!
Good luck and happy coding!