What if choice1 is rock, unexpected token if?


#1

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

}

what is the error here?


#2

Hi goldmarvin,

I think your function miss a pair of bracket { } before the first if and at the end.

Without them, your code of conditions if/else is not inside your function your are trying to define.

var variablename = function(arguments){ your function here, if/else statements }

That should work like this :smile:

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";
}
}
console.log(compare("rock", "rock"))