...

/

Rock Paper Scissors

Rock Paper Scissors

Create a rock paper scissors game.

We'll cover the following...

Coding project

Let’s try another coding project. This time, we’ll try to create an interactive version of the classic game Rock Paper Scissors, where we play against the computer. This will give us a chance to use what we’ve learned in this chapter to determine who wins the game.

To get started, let’s ask the player what their choice is.

const player = prompt('Choose rock, paper or scissors').toLowerCase().trim();

This uses a prompt box to ask the user to enter “rock”, “paper”, or “scissors”.

Press + to interact
Rock, paper, scissors
Rock, paper, scissors

We also “clean” their answer using the toLowerCase() and trim() methods. This makes sure their answer is all lowercase and removes any extra whitespace. This string is stored in the variable player. ...