So codeacadamy says completed the Rock, paper scissors but it isn't working properly


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/5?curriculum_id=506324b3a7dffd00020bf661

So codeacadamy says I have completed the Rock, paper scissors but the only response that works is when there is a tie otherwise I just get something like this depending on the choice. "Computer: rock
ReferenceError: paper is not defined". Cheers for any help.


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function (choice1, choice2){

if (choice1===choice2)
return "The result is a tie!"

if (choice1==="rock")
if (choice2===scissors)
return "Scissors wins"
else return "paper wins"

else if (choice1===paper)
if (choice2===rock)
return "paper wins"
if (choice2===scissors)
return "scissors wins"

else if (choice1===scissors)
if (choice2===paper)
return "scissors wins"
if (choice2===rock)
return "rock wins"}

compare(userChoice,computerChoice);


#2

paper, rock and scissors are all string? Not variables


#3

Can you explain please


#4

here:

else if (choice1===paper)

paper is a variable, but you haven't defined it anywhere, are you sure paper should be a variable here?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.