Something wrong with my code? Unexpected keyword else


For some reason my code keeps saying unexpected keyword else. anyone know what's wrong?

var compare = function(choice1, choice2)
    return "The result is a tie!";
else if(choice1==="rock") {
    if(choice2==="scissors") {
        return "rock wins";
    else {
        return "paper wins";


Brackets are usually the problem. We never write a semi-colon before else, and there is one missing at the end. Only the last brace should have a semi-colon. The first if is missing an opening brace, as well.


Can you show me your code please? I think that'd help. Thanks


var compare = function (args) {

    // function body code

 }; // semi-colon this line only

function body code

    if ( tie condition) {

    else if ( rock condition ) {
        if ( paper condition ) {

        } else {


The above is pseudo code; the pattern is what is important.


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