This is a simple project of rock-paper-scissors game that can be played against the computer. The game keeps a record of the user's and computer's scores and updates them as the game result.
The program initializes the user and computer scores to 0, and then defines functions to get the computer's choice, to convert the choices from lowercase to their corresponding title case versions, and to handle the outcome of the game (win, lose, or draw). Finally, the code adds event listeners to the buttons representing Rock, Paper, and Scissors and calls the game function with the user's choice.
When a user clicks a button, the main function gets called, which in turn calls the game function with the user's choice. The game function then gets the computer's choice, compares it with the user's choice, and calls the appropriate function to handle the outcome (win, lose, or draw). Each of these functions updates the user and computer scores and displays a message with the outcome of the game.
It displays a message after each round to let the user know whether they won, lost, or tied, and highlights the user's choice in green if they win, red if they lose, or gray if the round is a tie.
Overall, this code is a simple but effective implementation of a classic game. However, there is room for improvement, such as adding better styling and user feedback, adding more complex game mechanics, or adding more error handling.
Submitted by Samim Raja Mollick (samim)
Download packets of source code on Coders Packet
Comments