What if Choice1 is rock:SyntaxError: Unexpected token else?


#1


What if Choice1 is rock:SyntaxError: Unexpected token else?


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


#3

var compare = function(choice1,choice2){
    if (choice1 === choice2)
       return("The result is a tie!")
} // problem here - you closed function compare(). Remove }
else if (choice1 === "rock") {
    
    if (choice2 === "scissors"){
        return("rock wins!")
    }
    else {
        return ("paper wins")
    }
} // close else-if

} // and put here to close function compare()

You closed function compare() and else if (choice1 === "rock") is outside the function.


#4

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