7. What if choice is paper


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661


Keep getting, SyntaxError: Unexpected token else


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


What is wrong here
#2

You are missing one more curly bracket to close the first elseif and at the end to close things up! :slight_smile:

You then should have:

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

#3

Thanks, I actually figured that out right before you answered after trying to figure it out for AGES!

This is what I did.

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

I don't quite understand though still. Was my problem that I wasn't closing the else if's?


#4

You're welcome.

You should close/wrap every condition inside its dependent condition. And you do that in JS using the curly braces.

Missing one leaves the computer confused or interpreting to mean something else.


#5

I see, that makes sense. Thank you.


#6

You;re welcome.

Have fun coding! :slight_smile:


#7

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