Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda