Rock, Paper, Scissors - 2.8 - Invalid Syntax?


#1

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

Hi, I just started the JavaScript course yesterday and I’m stumped on the last part of this course. I tried everything I could to fix it, but I couldn’t come up with anything. Is there anyway to fix the Syntax error? (SyntaxError: Unexpected token else)
<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

```

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

compare(userChoice,computerChoice);

<do not remove the three backticks above>

#2

There are a few errors.

You need an if statement for choice1 answer before the else statement.

Something like this:

else if (choice2 === “scissors”) {

    if (choice1 === "rock") {
    
    return "rock wins";
    
} else {
    
    return "paper wins";

I’m looking for the rest, but start with that.


#4

Remove the last bracket in the code, and add one here:

else if (choice2 === “scissors”) {

    if (choice1 === "rock") {
    
    return "rock wins";
    
} else {
    
    return "paper wins";
    
}
**}**

That should do it.


#5

Thank you so much! Now I can complete the rest of JavaScript!


#6

Have fun it get harder, but it’s worth it in the end.