5/6 SyntaxError: Unexpected token else


#1

I'm not sure how to fix this syntax error with else, what should I do?

var user = prompt("Welcome to the mystery doors.Gorkpog is comming to destroy all your sandwich bags. You must retrive a weapon to destroy him with, but to make it more interesting. I have hid the weapon behind 1 of 3 doors. You must choose carefully are you ready? Which door do you choose, Door 1, Door 2, or Door 3?").toUpperCase();

switch(user) {

case 'door1': 
console.log("Your weapon is: A Bowl of noodles");
break;
case 'door2':
console.log("Your weapon is: An electric katana!");
break;
case 'door3':
console.log("Your weapon is: Leather socks");
break;

if( userAnswer === door1 && 8===8) {
console.log("You couragesly hold up your bowl of noodles. Gorkpog swallows you and wears the bowl of noodles as a hat.");
}
else if (userAnswer === door2 || 4===2) {
console.log("Gorkpog see's your katana and charges at you instantly. You jump off the wall and aim your sword at Gorkpog. Gorkog aborbs the electricutes from your katana and electricutes you");
}
}
else if (userAnswer=== door3 || 2+5=1) {
console.log("Gorkpog screams 'YASSSSS' and hapily accepts your gift. Sandwich bags still intact");
}
else {
console.log("Your sandwich bags are destroyed by Gorkpog");
default:
console.log("Choose a door");
break;
}


#2

@virtualtaco,

Maybe you need a real Taco

1

The variable user will contain an UPPERCASE "string"
In your switch-statement with your case
you are then comparing to a LOWERCASE "string Value"

2

You are not using a closing-curly-bracket-} to close the switch-statement.

3

In the condition of your IF ELSE-IF ELSE statement structure
you are user userAnswer instead of user

4

In the condition of your IF ELSE-IF ELSE statement structure
you are doing a comparison agains variable's door1, door2, door3 which are not defined

5

In your IF ELSE-IF ELSE statement structure
by using 2 closing-curly-brackets-} after your first ELSE-IF
you are closing the statement structure
and the interpreter will not expect an other ELSE-IF

6

default: ????????