SyntaxError: Unexpected token else


#1

I'm on the Code Your Own Adventure2! Lesson in Unit 5 and I'm getting an error on the final submission. The error reads, "SyntaxError: Unexpected token else." If someone could take a look at the below and let me know what the issue is that would be great. Thanks!

var user = prompt("You find a great job. What do you do? Do you apply, refer, or ignore?").toUpperCase();

switch(user) {
case 'APPLY':
var interested = prompt("Are you interested in the job?").toUpperCase();
var qualified = prompt("Are you qualified?").toUpperCase();
if (interested === YES && qualified === YES) {
console.log("Go for it, gurl!");
} else {
console.log("What the heck are you applying for then, weirdo?");
}
break;
case 'REFER':
var friend = prompt("Do you have a friend who would be interested?").toUpperCase();
var coworker = prompt("Maybe you know a coworker who'd be interested?").toUpperCase();
if (friend === YES || coworker === YES); {
console.log("You should definitely send it along!");
} else {
console.log("Maybe you should just ignore it then.");
}
break;
case 'IGNORE':
var field = prompt("Is this job in your field?").toUpperCase();
if (!field === YES) {
console.log("Yeah, I guess you should look for something else.");
} else {
console.log("Then what's the problem??");
}
break;
default:
console.log("Sorry, I didn't understand your answer. Please type apply, refer, or ignore.");
break;
}


#2

An else-statement may only follow immediately after an if-statement. So whatever is preceding that else, it's not an if.

An if-statement consists of the header (if (<condition>)) followed by ONE statement, followed by an optional else

; creates an empty statement if there isn't one to end

{} creates a compound statement, whatever is between them will, as a whole, be considered a single statement.

That's all the information you need to figure this out, get that magnifying glass out!


#3

Thanks for your reply. I believe that all of my else statements are directly preceded by an if statement which is why I am confused. I made sure all of my if statements were closed with the } before my else began. Not sure what else to do.


#4

Oh gosh, I see it - stupid ; !! haha thank you!!!


#5

@ecorrea831

In your refer CASE condition you have an if statement that is terminated with a semicolon.

Finally there are other problems i spot. such as your used of !field in the IGNORE case, that's not the correct way to use the NOT condition. Also you should use quotations mark around YES otherwise the interpreter will think your condition is a variable.

case 'REFER':
var friend = prompt("Do you have a friend who would be interested?").toUpperCase();
var coworker = prompt("Maybe you know a coworker who'd be interested?").toUpperCase();
if (friend === YES || coworker === YES); { // remove the semicolon here
console.log("You should definitely send it along!");
} else {
console.log("Maybe you should just ignore it then.");
}