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

180
Vistas
What is wrong with my if/else statements?

My first time and first project: Rock, Paper, Scissors. I have spent hours trying to figure out what could be wrong with my if/else statements. Regardless of conditions evaluated, it returns the first statement(It's a tie"). My code is as below;

const computerSelection = computerPlay();
const playerSelection = humanPlay();

function computerPlay() {
  let gameItems = ["rock", "paper", "scissors"];
  let randItem = gameItems[Math.floor(Math.random() * gameItems.length)];
  return randItem.toLowerCase();
}

function humanPlay() {
  let selectItem = prompt(
    "Please pick one battle item: rock, paper, or scissors"
  );
  return selectItem.toLowerCase();
}

function playRound(playerSelection, computerSelection) {
  if (playerSelection === computerSelection) {
    return "It's a tie!";
  } else if (computerSelection === "rock" && playerSelection === "scissors") {
    return "You lose!";
  } else if (computerSelection === "scissors" && playerSelection === "rock") {
    return "You win";
  } else if (computerSelection === "scissors" && playerSelection === "paper") {
    return "You lose";
  } else if (computerSelection === "paper" && playerSelection === "scissors") {
    return "You win";
  } else if (computerSelection === "paper" && playerSelection === "rock") {
    return "You lose";
  } else if (computerSelection === "rock" && playerSelection === "paper") {
    return "You win";
  } else {
    return "Please play again";
  }
}

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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Add console.log(playerSelection, computerSelection) to the first line of the playRound() function. You'll see that both values are undefined, because you aren't passing those values into the function when you call it.

To fix, change the very last line to: console.log(playRound(computerSelection, playerSelection));

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