Coding my own adventure


#1


I keep getting an error in my code saying "unexpected token break", I also get a message saying I need to use && or something like that. tried multiple ways and still do not understand why it is not working.


var user = prompt("Where are you going?").toLowerCase();
switch(user) {

    case 'chicago':
        console.log("I hear that it is very windy there.");
        break;
    case 'los angeles':
        console.log("Oh the city of angels!");
        break;
    case 'portland':
    if(portland===true){
        console.log("I also live there so I should know.");
    }
    else{
        console.log("I actually have never been.");
    }        console.log("Better be pepared for all weather types!");
        break;
    case 'new york':
        console.log("Try not to get mugged!!");
        break;
    default:
    console.log("Must be a small town because I have never heard of it / before");
    break;
}


#2

Now after removing the random break it is telling me that portland is not defined.


#3

And the error is quite right to. You said that if Portland is true then run this black of code else run this block of code. When you put Portland into your if statement then it treated it like a boolean when really you want Portland to be a string.

Remember to keep the break removed as well.


#4

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