4. Switch I don't understand where syntax error is located


#1


//Below is the code I am working on but the error always says (SyntaxError: expected expression, got keyword 'else')May anyone help me//
var user = prompt("You just returned home late at night and your parents are in the parlour waiting for your excuse.What do you tell them? A - An alien spaceship surrounded your school with a forcefield until 5pm because they had to go home to drink tea. B - A lion suddenly came to school and picked a fight with you. Or C - You had Basketball practice until 5:30pm but had to come home early to eat.", "Write the corresponding alphabet letters please!").toUpperCase();
switch(user){
    case'A':
        console.log("Your parents look at you with ridicule and anger. Then they unleash their wip! You are doomed for the moment!");
        var ansWer = prompt("Did an alien spaceship really surround the school?", "Yes/No?").toUpperCase();
        if(ansWer = 'YES'){
            console.log("The aliens return for your parents!They are taken away!");
        };
        else{
            console.log("Your parents ground you for two weeks without electronics for telling lies!");
        };
        break;
    case'B':
        var question = prompt("Are you in anyway hurt, bruised or even both?", "HURT/BRUISED/BOTH").toUpperCase();
        if(question = 'HURT'){
            console.log("Seeing that you are very weak and feel lightweight unusually, they immediately hold you and carry you to your room.");
        };
        else if(question = 'BRUISED'){
            console.log("Your parents immediately get you fast treatment for you. You are being Pampered!");
        };
        else{
            console.log("You drop to the ground and faint immediately!");
        };
        break;
    case'C':
        var anotherQuestion = prompt("Do you want to go back to school?", "Yes/No").toUpperCase();
        if(anotherQuestion = 'YES'){
            console.log("You tell your parents that the guys are waiting for you and you need to get back quick! Your mother quickly gets you your favourite dish!");
            var userDish = prompt("What's your favourite dish?");
            console.log("Then, she gets you your favourite " + userDish + " and says 'Come back quickly!'");
        };
        else{
            var userDish = prompt("What's your favourite dish?");
            console.log("You get down and dirty with a delicious " + userDish);
        };
        break;
    default:
       console.log("Choose exactly the options I gave you please! Nothing else!");
}


#2

@favourrege I found one error here:

there should not be a semi-colyn( ; ).

also here:

hope this helps

Steven


#3

Thank You Steven for your help! :smile:
I got through!
This shows the wonderful work of COMMUNITY :park:!


#4

We never write a semi-colon before else.

if () {

}
else if () {

}
else {

}

Notice no semi-colons anywhere in the syntax?


#5

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