What if choice one is paper?


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

I am having a few problems with this unit. It says I have an unexpected token else.

<Below this line, add a link to the EXACT exercise that you are stuck at.>
It is build rock, paper, scissors (unit 4 of js) #7, what if choice 1 is paper
<In what way does your code behave incorrectly? Include ALL error messages.>

Like I said above, it says I have an unexpected token else.
<What do you expect to happen instead?>
It seems like correct code to me, here it is. please let me know where I am wrong ASAP - thanks

``` 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”;
}
}

<do not remove the three backticks above>

#2

Hi this parts

if(choice2 === "scissors")
    return"rock wins";
}

================

if(choice2 === "rock")
    return" paper wins";
} 

Its missing the open { of the if statement.


#3

Oh I see! Thanks I’ll try it out


#4

here is my new code but it says unexpected end of input

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”;
}


#5

Here

else if(choice1 === "paper") {
    if(choice2 === "rock"){
         return" paper wins";
    } 
    else {
         return "scissors wins";
    }
}<== add one here for closing the else if statement 

}<== another one for closing the compare function 

#6

Thank you so much it works!:grin: