Rock Paper Scissors game

Can someone help me make the game end at whoever gets to 5 points first? the link is below

Rock Paper Scissors

you can disable all button when you reach the desired score

hope that help and have a nice day

Hi there @ayanda!

To get this working simply, you need to have computerScore and playerScore defined outside the scope of the game() function. At the moment they are being redefined as 0 each time the function runs, so the scores don’t persist.

If you wanted to set it up so that the game runs until either player has got 5 points, you need to start the game with some kind of init() function, inside which you check whether the computer or player has got 5 points yet. If not, then let the game continue. If so, then disable the buttons, and announce who has won in some way.

You could also then display a “new game” button, which if pressed resets the scores back to 0, and un-disables the buttons, ready for a new game.

The code is also pretty repetitive — in terms of querying the scores, I’d suggest creating a global object along these lines to query what the score should be:

let scoreCalc = {
  'rock': {
    'paper': 0,
    'scissors': 1
  'paper': {
    'rock': 1,
    'scissors': 0
  'scissors': {
    'paper': 1,
    'rock': 0

Then inside your game() function you could still return the selections made by the player and computer like this:

let playerSelection =;
let computerSelection = computerPlay();

And then you could return what the score should be like this:


So if the player chooses “rock” and the computer chooses “scissors”, scoreCalc[playerSelection][computerSelection] would equate to scoreCalc['rock']['scissors'], which would return 1, indicating the player has won this round. You can then increment scores, display messages, etc., based on this, which would cut down on your code a lot.

All I’m seeing is the qoute below, when I click on HTMLbuttonElement.disabled… there is no actual layman’s explanation of how to stop the game…

Is a Boolean indicating whether or not the control is disabled, meaning that it does not accept any clicks.

Hey, thanks for the comprehensive suggestions. Let me look up about the init() function you mentioned.

Ooooh, sorry, just to be clear — this is a function you would define, not a browser-provided function. “init” is short for “initialize”, and is a common convention used to mean the function that starts an app running.

it will set the element to disable so if it disabled you would not be able to click on it

but follow what chrisdavidmills he is the expert here

and have a nice day both of you

Oh! Thank you. Got it. I feel ridiculous now. I put an IF function at the beginning and that seems to stop the game when the scores reach 5… I haven’t been good at grasping the eventListner concepts but I guess I’ll try figure out a way to make the reset button occur.