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

69
Vistas
JS Rock Paper Scissor project. Doesnt prompt new selections for each round

At the infant stages of learning JS. My RPS project works for the most part... The problem I cannot get around is that the game is calling for a 'human' input and computer selection once, then runs this selection 5x instead of calling for a new selection for each round. I've beat my head on this for several days to no avail.

let person = prompt(
    'What will it be? Rock, Paper, or Scissors.'
);
person = person.toUpperCase();
console.log(person); // show human selection
let computer = [
    Math.floor(Math.random() * 3) + 1
];

let roundCount = 0;
let humanWins = 0;
let compWins = 0;

if (computer == 1) {
    computer = 'ROCK';
} else if (computer == 2) {
    computer = 'PAPER';
} else if (computer == 3) {
    computer = 'SCISSORS';
} else {
    computer = 'No true statements';
}
console.log(computer); // show comp selection

function playGame(peep, comp) {
    roundCount++;
    if (peep === comp) {
        console.log('Tie', +roundCount);
        return 'Tie';
    } else if (
        (peep === 'ROCK' &&
            comp === 'SCISSORS') ||
        (peep === 'PAPER' && comp === 'ROCK') ||
        (peep === 'SCISSORS' && comp === 'PAPER')
    ) {
        humanWins++;
        console.log(
            'Human wins this round',
            +roundCount,
            +humanWins
        );
        return 'Human wins this round';
    } else {
        compWins++;
        console.log(
            'Skynet wins this round',
            +roundCount,
            +compWins
        );
        return 'Skynet wins this round';
    }
}

function game() {
    for (let i = 0; i <= 5; i++)
        if (humanWins === 5 || compWins === 5) {
            console.log('game over');
        } else {
            playGame(person, computer);
        }
    return humanWins, compWins;
}

game();
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
  <script src='script.js'></script>
  <script>
   
  </script>
</body>
</html>

I don't understand why it takes a single round and runs that result 5 times.

about 4 years ago · Juan Pablo Isaza
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