Help with Rock Paper Scissors Game

I’m trying to create a rock paper scissor game that displays the images of rock paper and scissors as the computer result. This is some of the code that I think is relevant to what im trying to do. So when the user makes a selection, I want the computers choice to be displayed while also showing if the user won lose or drew. I can’t figure out a way to compare the user’s choice to the computer’s choice so it can then determine a winner.




     <div class="user-choice">
        <img  class="rock" src="icons/rock.png">
        <img  class="paper" src="icons/paper.png" >
        <img  class="scissors"src="icons/scissors.png">
<div class="cpu-result">
            <img class="cpu-rock" src="icons/rock.png">
            <img class="cpu-paper" src="icons/paper.png" >
            <img class="cpu-scissors" src="icons/scissors.png">

     <div class="result"></div>

let userRock = document.querySelector(’.rock’)
let userPaper = document.querySelector(’.paper’)
let userScissors = document.querySelector(’.scissors’)
let cpuScissors = document.querySelector(’.cpu-scissors’)
let cpuPaper = document.querySelector(’.cpu-paper’)
let cpuRock = document.querySelector(’.cpu-rock’)
let computerScore = 0;
let userScore = 0;

let currentItem;

userPaper.addEventListener(‘click’, start)
userScissors.addEventListener(‘click’, cpuChoice)
userRock.addEventListener(‘click’, cpuChoice)

function start() {

// Computer Choice
function cpuChoice() {
const rand = Math.random()
if (currentItem) { = ‘none’
if (rand < .34) { = ‘inline-block’
currentItem = cpuPaper;
} else if (rand >= .67) { = ‘inline-block’
currentItem = cpuRock;

} else { = 'inline-block'
    currentItem = cpuScissors;


// Get Winner
function getWinner() {


i would suggest you, inside the cpuChoice(), have a variable that simply has a string for the selection name: ‘rock’ or ‘paper’ or ‘scissors’. Same for the playerChoice(). Then checking for a win can simply be comparing strings:

switch (playerSelection){
  case 'rock':
    switch (cpuSelection){
      case 'rock':
        // handle a match case.
      case 'paper':
        // handle a player loss
      case 'scissors':
        // handle a player win
  case 'paper':
    // Do the same here, and in 'scissors', as above: handle each possible case.
  case 'scissors':
    // Ditto the above.
1 Like