Code Your Own Adventure 2 "Unexpected Token Case"


#1



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


This code comes up with the error "SyntaxError: Unexpected token case"
please help


var user = prompt("A wild troll appeared. What do you do? (RUN, FIGHT, BAG or POKEMON)").toUpperCase();

switch(user) {
   
    case "RUN":
        console.log("Got away safely");
        break;
        
    case "FIGHT":
        console.log("You Win!");
        break;
        
    case "BAG":
        var items = prompt("Do you have any good items? (YES or NO)").toUpperCase();
        if (items === "YES") {
            items = true;
        }
        else {
            items = false;
        }
        var trollSpray = prompt("Do you have any troll spray? (YES or NO)").toUpperCase();
        if (trollSpray === "YES") {
            trollSpray = true;
        }
        else {
            trollSpray = false;
        }
        if (trollSpray || items) {
            console.log("You defeated the troll and gained 10XP")
        }
        else {
            console.log("You were defeated. The troll stole £100")
        break;
        
    case "POKEMON":
        var likePokemon = prompt("Do you like Pokemon? (YES or NO)").toUpperCase();
        if (likePokemon === "YES") {
            likePokemon = true;
        }
        else {
            likePokemon = false;
        }
        var playedPokemon = prompt("Have you played pokemone? (YES or NO)").toUpperCase();
        if (playedPokemon === "YES") {
            playedPokemon = true;
        }
        else {
            playedPokemon = false;
        }
        if (playedPokemon && likePokemon) {
            console.log("You Win!");
        }
        else {
            console.log("You Loose!");
        }
        break;
        
    default:
        console.log("There is a time and place for everything, but not now");
        break;
      
}


#2

HI this part

if (trollSpray || items) {
            console.log("You defeated the troll and gained 10XP")
        }
        else {
            console.log("You were defeated. The troll stole £100")
        break;

you didn't close the else statement


#3

Thank You


:smile: