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

226
Views
I am making a rock, paper, scissors game and the values of the outputs are not all corect

I typed the statements and everything is working fine only when I try the console with the answer of rock. When I try to see other logs(paper or scissors) it gives me the output based on the first 3 if conditions(from the rock) and the others for some reason doesn't apply.

//My "choice"// 
function playerPlay() {
  let Answer = prompt(`Do you choose Rock,Paper or Scissors ?`).toLowerCase();
  console.log(Answer);
}
playerPlay()
//Computer random choice//
function computerPlay() {
  computerPlay = Math.floor(Math.random() * 3)
  if (computerPlay === 0) {
    console.log("rock");
  } else if (computerPlay === 1) {
    console.log("paper");
  } else if (computerPlay === 2) {
    console.log("scissors");
  }
}
computerPlay()

//The conditions for the game//

function rules() {
  if (Answer = "rock" && computerPlay === 0) {
    return ("Draw");
  } else if (Answer = "rock" && computerPlay === 1) {
    return ("You lost");
  } else if (Answer = "rock" && computerPlay === 2) {
    return ("You won");
  }

  if (Answer = "paper" && computerPlay1 === 0) {
    return ("You Won!");
  } else if (Answer = "paper" && computerPlay === 1) {
    return ("Draw");
  } else if (Answer = "paper" && computerPlay === 2) {
    return ("You Lost!");

  }
  if (Answer = "scissors" && computerPlay === 0) {
    return ("You Lost!")
  } else if (Answer = "scissors" && computerPlay === 1) {
    return ("You Won!");

  } else if (Answer = "scissors" && computerPlay === 2) {
    return ("Draw!");

  }
}
rules()

In the Image you can see that paper with paper is supposed to be a tie but the output actually is "You lost!"

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

answer = "..." should be answer == "..." in your if statements. = is used for assignment not for checking equality

You are defining the answer variable inside of your function using let. This means that the answer is only defined within the scope of the function and is not a global variable. Instead you should have it return answer, and instead of calling playerPlay() you should do answer = playerPlay()

The same issue exists with your computer play function. Your rules function returns the answer but nothing prints it out.

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!