"Rock, Paper, Scissors: What if choice1 is "paper"?


#1

Hi! I'm stuck here. I keep getting "unexpected token 'else' and I can't figure out why. The part I'm currently focusing on starts at "else if(choice1 === "paper") on line 27


#2

Hey @megan1441,

In your first else if loop that's with your if and else loop, you put the bracket too early. :smiley:

else if(choice1 === "rock"){
if(choice2 === "scissors"){
return "rock wins"
}
} <---- problem
else {
return "paper wins"
}  
} <---- supposed to be here

Also, you have a mysterious bracket after that:

{


#3

I tried fixing the brackets and it still didn't work. Now I've changed a little of the code and gotten this (starting line 27)

Which is closer to the correct code I think. But it tells me "Your code returned 'paper wins' instead of 'scissors wins' when the inputs are paper and scissors". I'm so confused!


#4

Seems like you still have the problem @ragezapper mentioned and please post your code rather then a screenshot as it makes it easier to run and quote the code.


#5

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!";
}
else if(choice1 === "rock"){
if(choice2 === "scissors"){
return "rock wins";
}else{
return "paper wins";
}
}
else if(choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins"
}else{
return "scissors wins"
}
}
else if(choice1 === "scissors"){
if(choice2 === "rock"){
return "rock wins"
}else{
return "scissors wins"
}
}
}
console.log(compare(userChoice,computerChoice));