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

140
Vistas
¿Cómo le pido al usuario que ingrese después de cada ronda en piedra, papel o tijera?

El juego funciona bien después de 1 ronda. Estoy tratando de jugar 5 rondas. Probé un ciclo for antes del ciclo while. Sin embargo, aún solo le pide al usuario que ingrese una vez.

 let computerPlay = () => { let compChoices = ["rock", "paper", "scissors"]; //array storing computer possible actions let i = Math.floor(Math.random() * 3); let choice = compChoices[i]; return choice; }; // let playerChoice = prompt("Select your action").toLowerCase(); let computerChoice = computerPlay(); let playRound = (playerSelection, computerSelection) => { let winner = ""; if (playerSelection === computerSelection) { winner = "tie"; } else if (playerSelection > computerSelection) { winner = "player"; } else { winner = "computer"; } return console.log(winner); }; let i = 0; while (i < 5) { playRound(playerChoice, computerChoice); i++; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

ACTUALIZADO

Como requisito, el autor solicita mantener los playerSelection y computerSelection para playRound . Sugiero que la solución sea poner playerChoice y computerChoice en el bucle while

 let computerPlay = () => { let compChoices = ["rock", "paper", "scissors"]; //array storing computer possible actions let i = Math.floor(Math.random() * 3); let choice = compChoices[i]; return choice; }; let playRound = (playerSelection, computerSelection) => { let winner = ""; if (playerSelection === computerSelection) { winner = "tie"; } else if (playerSelection > computerSelection) { winner = "player"; } else { winner = "computer"; } return console.log(winner); }; let i = 0; while (i < 5) { //here is the change let playerChoice = prompt("Select your action").toLowerCase(); let computerChoice = computerPlay(); playRound(playerChoice, computerChoice); i++; }

RESPUESTA ANTIGUA

Su problema es que pasa prompt fuera de su playRound . playerSelection y computerSelection también deberían estar en playRound , lo que ayudaría a restablecer los valores de la computadora y sus elecciones en cada ronda.

 let computerPlay = () => { let compChoices = ["rock", "paper", "scissors"]; //array storing computer possible actions let i = Math.floor(Math.random() * 3); let choice = compChoices[i]; return choice; }; let playRound = () => { let playerSelection = prompt("Select your action").toLowerCase(); let computerSelection = computerPlay(); let winner = ""; if (playerSelection === computerSelection) { winner = "tie"; } else if (playerSelection > computerSelection) { winner = "player"; } else { winner = "computer"; } return console.log(winner); }; let i = 0; while (i < 5) { playRound(); i++; }
about 4 years ago · Juan Pablo Isaza Denunciar
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