8/9 Syntax Error: Unexpected Token {


#1

Hello,
I've been working on the JavaScript course, but I ran into trouble finishing part 8/9 with a syntax error due to an unexpected "{" I've pasted my code below if anyone can clue me in where I messed up.

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!";
        }
    }
    else if (choice1 === "scissors"{
        
        if (choice2 === "rock") {
            return "Rock Wins" ;
        }
        else {
            return "Scissors Win";
        }
    }
}
compare(userChoice,computerChoice)

#2

I'm a noob but I think you're missing an opening curly bracket after your last 'else'


#3

Hi there!
Thanks for responding. You're completely right, but it is still giving the same error of an unexpected {. I have fixed it in the original post. If you see anything else please feel free to post!

Best.


#4

Your missing a closing ) here:

else if (choice1 === "scissors"{

that's why the { comes unexpected.


#5

Bingo! Thanks.

A second pair of eyes is always very helpful. I wish the errors would give you a line number though.