What if choice1 is paper? - SyntaxError: Unexpected token else


#1

Okay, I've been slaving over these curly braces for a while now and I'm missing something. Need a fresh pair of eyes, thanks in advance.
Output: SyntaxError: Unexpected token else

/*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);*/
//relevant code below//

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


#2

@vandersleid

I'm not an expert at JS nor am I on that lesson, however, looks like your bracketing '{ }' might be off.

I copied and pasted your code to a text file and separated the code to line the brackets up.
To me it looks like that may be the issue, when compared to the error given.


#3

I appreciate your response.

I know that it's probably a bracketing error, but as I count, there are 8 forward and 8 backwards facing brackets. So, unless you have a specific line in question, I'm still pretty lost.

Thank you, though.
(Inb4 I'm oblivious to something obvious, ha)


#4

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