Starting the Simon project. Decided step one would just be make sure I could get the computer and player to take turns properly, and already running into a snag.
You can check out the codepen here. I have it outputting the status of variables for each turn and current level for each step to see how they’re changing to help trouble-shoot things:
The turns are handled by a simple function that should check variables to see what to do next and then calls itself again to do each next turn. Right now, to simplify the player move, I’m only paying attention to the red div and not trying to compare the results against the computer’s sequence. So it should be simple. But it does the first computer turn fine, then seems to handle the player onclick move ok, then does the next computer turn ok. But the next player turn is broken – instead of being level 2, turn 0, it changes the variables to level 1, turn 1. After that,everything goes off the rails
I’m guessing I’m making some fundamental error in regards to the scope of the anonymous function that handles the player’s onclick event (and maybe starting a duplicate loop by calling the function again), but I’m not sure exactly what I’ve done wrong.
Would greatly appreciate any hints or pointers!