Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

288
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda