SyntaxError: Unexpected token if

SyntaxError: Unexpected token if

我目前正在学习 javascript,但我一直遇到这个错误!!!

这是我的脚本:

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

应该是:

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

或更整洁:

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