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

287
Views
Rock, Paper, Scissors game in Javascript

I am making a Rock paper, and scissors game for the Odin project which is supposed to run in the console.

Currently, everything works fine until I implemented the function called game().

I assumed it would call the playRound() function until playerscore, or computerscore reached 5. but it is currently only working twice. It prompts once up top for playerSelection and prompts again for playerSelection within function game();

How could I get game() to run until either playerscore or computerscore reaches 5? And display result for each round?

let playerScore = 0;
let computerScore = 0;


function computerPlay() {
    let choices = ['rock', 'paper', 'scissors']
    return choices[Math.floor(Math.random() * choices.length)]
}

let computerSelection = computerPlay();


let playerSelection = prompt("Make your selection, Rock, paper or Scissors").toLowerCase();

function playRound(playerSelection, computerSelection){
    if ((playerSelection == "rock" && computerSelection == "scissors") ||
       (playerSelection == "scissors" && computerSelection == "paper") ||
       (playerSelection == "paper" && computerSelection == "rock")){
        playerScore++;
        return ("You win! " + playerSelection + " beats " + computerSelection + ", the score is Player:" + playerScore + " Computer:" + computerScore);
       } else if (playerSelection == computerSelection){
        return "Draw!"
       } else {
        computerScore++
        return ("You lose! " + computerSelection+ ", beats " + playerSelection + " the score is Player:" + playerScore + " Computer:" + computerScore)
       }
}




function game(){
    if (playerScore < 5 && computerScore < 5) {
        let playerSelection = prompt("Make your selection, Rock, paper or Scissors").toLowerCase();
        playRound(playerSelection, computerSelection)
    } 
}
   
game();



console.log(playRound(playerSelection,computerSelection));

almost 4 years ago · Santiago Trujillo
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!