SyntaxError: unexpected token ILLEGAL


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#

When I press save and submit code, I get a syntax error saying: SyntaxError: Unexpected token ILLEGAL I do not have a use for the variable user.
I can't find anything wrong with the code. Here it is:

 var user = prompt("What's your name?");
var answer = prompt("While walking in the fields, a small group of 5 monsters attack you. Do you pull out your sword, pull out your bow, or run? SWORD, BOW, RUN").toUpperCase();
switch (answer) {
    case 'SWORD':
        var skill = prompt("Do you have experience with a sword? YES or NO").toUpperCase();
        var strong = prompt("Are you strong? YES or NO").toUpperCase();
        if (skill === 'YES' || strong === 'YES') {
            console.log("Great job! You only need one of the two. You defeated the monsters!);
        }
        else {
            console.log("Oh no! The monsters ate you!");
        }
        break;
    case 'BOW':
        var exp = prompt("Do you have experience with a bow? YES or NO").toUpperCase();
        var arrow = prompt("How many arrows do you have?").toUpperCase();
        if (exp === 'YES' && arrow > 4) {
            console.log("You did it! With your experiance and your arrows, you were able to defeat the monsters!");
        }
        else if (exp === 'YES' && arrow < 5) {
            console.log("Oh no! Because you didn't have enough arrows, the monsters ate you!");
        }
        else if (exp === 'NO' && arrow > 4) {
            console.log("Oh no! Because you didn't have experiance, the monsters ate you!");
        }
        else {
            console.log("Oh no! Because you didn't have any experiance or enough arrows, the monsters ate you!);
        }
        break;
    case 'RUN':
        var fast = prompt("Are you fast? YES or NO").toUpperCase();
        var start = prompt("Did you get a head start?").toUpperCase();
        if (fast === 'YES' || skill === 'YES') {
            console.log("Great job! You only needed one. You escaped from the monsters!");
        }
        else {
            console.log("Oh no! You couldn't escape from the monsters! They ate you!");
        }
        break;
    default:
        console.log("I'm sorry, I don't understand what you're saying. Try choosing SWORD, BOW, or RUN");
        break;
}

#2

look around you need to put the ending quotation mark here:

and here:


#3

Thank you! My code works perfectly now!


#4

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