Simon Game questions

Hey there! First time poster here.

I’m struggling a bit with a couple portions of my Simon game and was wondering if someone had time to take a look.
Here is the link : https://codepen.io/horoxix/pen/KmPZjg?editors=0111

Basically the function checkTurn() seems to be getting stuck. When I log them in the console, I can see that their length’s aren’t equal, so it should go down into that if statement, however it’s getting stuck there for some reason. Any tips?

Also, any tips for my code in general would be appreciated! I’m still learning and have been struggling through the last few apps but when you’re uncomfortable is when you’re truly learning, so hopefully I can stick with it.

Thanks!

Rather than storing each of the player’s moves, why not just count the number of moves and compare their current move to the compMove. If they’ve made 5 moves they should be at compMove[4], so just compare their current note to compMove[4]. Not sure that made sense. But it might simplify things.

I couldn’t really test it. It’s telling me it is incorrect when it isn’t.

1 Like

Okay so you’re saying that with every “click” compare that to the current index of the compMove that it’s on? So the third click will be compMove[2] and just compare like that? that seems like it could simplify things. Thank you!

edit I think I may have misread your problem. One thing that seems to help me in the debugging/making things work is to only call one function at a time. Your onclick function calls three different functions. Instead it could only call one function that then call the next required function that in turn, calls the next required function. that way you can then console.log each intermediate step to make sure each component is doing what it should be doing.

Does that make sense?

That’s a great point and great idea. Thank you! I will work on cleaning those up. Sometimes when I’m writing code I just get in the function mindset and don’t think about the ease of debugging or keeping it clean. I guess thats something I need to work on.