5. Logical Operators (SyntaxError: Illegal break statement)


#1


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

Hi, I'm having trouble figuring out what syntax error I'm encountering. Excuse the choices, it was a spontaneous decision to use Pokemon. :slight_smile:


var user = prompt("You are walking in tall grass, suddenly a wild Pigey appears! Do you (Battle, Run, or Call)?").toLowerCase();

switch(user){
    case "battle":
        var starter = prompt("Do you choose (Squirtle) or (Charmander)?").toLowerCase();
        var rare = prompt("Do you choose (Mew) or (Dragonite)?").toLowerCase();
        if(starter === "squirtle" || rare === "mew"){
            console.log("Nice one! You destroyed Pigey!");
        }
        else if(starter === "charmander" || rare === "dragonite"){
            console.log("Nice one! You destroyed Pigey!");
        }
        else if(starter === "squirtle" || rare === "dragonite"){
            console.log("Nice one! You destroyed Pigey!");
        }
        else if(starter === "charmander" || rare === "mew"){
          console.log("Nice one! You destroyed Pigey!"); 
        }
       else{
            console.log("You got tackeled by Pigey! You Lose!");
        }
        }
        break;
    case "run":
        prompt("Are you fast? (Yes) or (No)?").toLowerCase();
        var headstart = prompt("Did you get a headstart? (Yes) or (No)?").toLowerCase();
        var fast = prompt("Are you fast? (Yes) or (No)?").toLowerCase();
        if(headstart === "yes" && fast ==== "yes"){
            console.log("You ran away successfully");
        } else if(headstart === "yes" || fast === "yes"){
            console.log("At least you're one of those two, you got away successfully!");
        } else{
            console.log("You were not fast nor got a headstart, you got destroyed by Pigey.");
        }
}
        break;
    case "call":
        var cellphone = prompt("Do you have a cell phone? (Yes) or (No)?").toLowerCase();
        var voice = prompt("Do you have a loud voice? (Yes) or (No)?").toLowerCase();
        if(cellphone === "yes" && voice === "yes"){
            console.log("You called for help successfully!");
        } else if(cellphone ==="yes" && voice === "no"){
            console.log("You called for help successfully!");
        } else if(cellphone ==="no" && voice === "yes"){
            console.log("Your voice wasn't loud enough, you failed at calling for help");
        } else {
            console.log("You didn't call for help, you have been destroyed by Pigey!");
        }
        }
        break;
    default:
    console.log("You didn't enter a valid choice, please choose again");
}


#2

switch(user){
    case "battle":
        var starter = prompt("Do you choose (Squirtle) or (Charmander)?").toLowerCase();
        var rare = prompt("Do you choose (Mew) or (Dragonite)?").toLowerCase();
        if(starter === "squirtle" || rare === "mew"){
            console.log("Nice one! You destroyed Pigey!");
        }
        else if(starter === "charmander" || rare === "dragonite"){
            console.log("Nice one! You destroyed Pigey!");
        }
        else if(starter === "squirtle" || rare === "dragonite"){
            console.log("Nice one! You destroyed Pigey!");
        }
        else if(starter === "charmander" || rare === "mew"){
          console.log("Nice one! You destroyed Pigey!"); 
        }
       else{
            console.log("You got tackeled by Pigey! You Lose!");
        }
        } // remove it
        break;
    case "run":
        prompt("Are you fast? (Yes) or (No)?").toLowerCase();
        var headstart = prompt("Did you get a headstart? (Yes) or (No)?").toLowerCase();
        var fast = prompt("Are you fast? (Yes) or (No)?").toLowerCase();
        if(headstart === "yes" && fast ==== "yes"){  // should be ===, you have ====
            console.log("You ran away successfully");
        } else if(headstart === "yes" || fast === "yes"){
            console.log("At least you're one of those two, you got away successfully!");
        } else{
            console.log("You were not fast nor got a headstart, you got destroyed by Pigey.");
        }
} // remove it
        break;
    case "call":
        var CELLPHONE = prompt("Do you have a CELL PHONE? (Yes) or (No)?").toLowerCase();
        var voice = prompt("Do you have a loud voice? (Yes) or (No)?").toLowerCase();
        if(cellphone === "yes" && voice === "yes"){
            console.log("You called for help successfully!");
        } else if(cellphone ==="yes" && voice === "no"){
            console.log("You called for help successfully!");
        } else if(cellphone ==="no" && voice === "yes"){
            console.log("Your voice wasn't loud enough, you failed at calling for help");
        } else {
            console.log("You didn't call for help, you have been destroyed by Pigey!");
        }
        } // remove it
        break;
    default:
    console.log("You didn't enter a valid choice, please choose again");
}

#3

You rock! Thank you for the fast response!


#4

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