Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!