What if choice 1 is paper? Syntax error


#1

Code:

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

Error:
SyntaxError: Unexpected token else


#2

Noticed a couple small things. Not sure they will help.

'scissors' - single quotes

}; << no semi here ??
else if (choice1 === "paper") {


#3

Single quotes don't matter, I would use two equals ( == ) instead of three ( === ) though.


#4

Three is the standard they are teaching in the javascript class.

== equal to
=== equal value and equal type


#5

It's faster to just use two for this.


#6

I thought I didn't need a semicolon there?


#7

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

synstax error: unexpected toke else


#8

The use of single quotes or double quotes makes no difference as long as you don't mix them inside of one string. And the semicolons in the conditional statements are really a problem maybe have a look at this: