Help with resetting scores for rock paper scissors with UI interface


#1

Hello! I’ve been re-working my JavaScript rock paper scissors game to work with a UI inside the web-page. However, I am currently stuck at the last needed item to finish the game up. Currently, the game works through the first play through. However, once the user decides to play again, the resetScores() function does not seem to actually reset the scores, but rather returns ‘undefined’ in the console. As such, the scores do not reset as shown in the UI and the game is unable to be played through again unless the user refreshes the page.

Link to the code is here: https://github.com/HunterMillerc/rock-paper-scissors

The game starts at line 57, and the gameEnd() (what shows up after the playerScore = 3 or computerScore = 3) function is at line 282. Calling the resetScores() function does not seem to reset the scores correctly. I’ve searched for solutions for quite some time and if anyone is able to help I’d greatly appreciate it!


#2

You only update the score UI after the first round has been played, so although you reset playerScore and computerScore you don’t actually update the screen. If you play a game until there is a winner and then click to replay, as soon as you choose rock, paper or scissors the UI updates.

You should just reset the textcontent of the playerscores


#3

I’ve attempted to reset the textcontent of the playerscores in the resetScores(). It does reset the UI score shown on the page, but when selecting another choice, the game ends right away still.

I have logged the scores after the resetScores() and found they do in fact seem to reset to 0, so I’m not sure what is causing the game to not iterate through until one of the scores become 3 again.


#4

To be honest I’m not sure. There is a lot of code there. Maybe it needs simplifying a bit.