Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
The odin project rock, paper, scissor always a tie

I have been trying to complete the odin projects console-based rock, paper, scissors game and I think I have most of it done. For some reason however, the result of the game is always a tie and I cannot figure out what the problem is. Furthermore, the program runs once before going on the loop for five rounds. I would appreciate if anyone could offer some advice as to what I'm doing wrong. Here's the code:

let choices = ["rock", "paper", "scissors"]
let userScore = 0;
let computerScore = 0;
let playerSelection = playerPlay();
let computerSelection = computerPlay();


function playerPlay(){
    //player input
    let playerChoice = prompt("Please type either 'rock', 'paper' or 'scissors' to play: ").toLowerCase();
    return playerChoice;
}

function computerPlay(){
    //computer chooses one of the three choices at random
    let random = choices[Math.floor(Math.random() * choices.length)];
    return random;
}

function playRound(playerSelection, computerSelection) {
    //one round of the game

    computerPlay();
    playerPlay();
    
    
    if (playerSelection === computerSelection) {
        return("It is a tie!");
    }

    else if (computerSelection === "rock" && playerSelection === "paper") {
        userScore++;
        return("You win! Paper beats rock");
    }

    else if (computerSelection === "scissors" && playerSelection === "rock") {
        userScore++;
        return("You win! Rock beats scissors");
    }

    else if (computerSelection === "paper" && playerSelection === "scissors") {
        userScore++;
        return("You win! Scissors beats paper");
    }

    else if (computerSelection === "rock" && playerSelection === "scissors") {
        computerScore++;
        return("You lose! Rock beats scissors");
    }
    
    else if (computerSelection === "paper" && playerSelection === "rock") {
        computerScore++;
        return("You lose! Paper beats rock");
    }

    else if (computerSelection === "scissors" && playerSelection === "paper") {
        computerScore++;
        return("You lose! Scissors beats paper");
    }
}

function game(){
    //play the game for five rounds
    for (let i = 0; i < 5; i++) {
    playRound();
    console.log(`You ${userScore} vs. ${computerScore} Computer`);     
    }
    
}

game();
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!