5. Logical Operators


#1



I keep getting this error code: SyntaxError: Unexpected token {


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


var user = prompt("What is your name?").toLowerCase();
switch(user) {
    case 'Jeff':
        var hungry = prompt("Are you Hungry?, (Yes or No)").toLowerCase();
        var food = prompt("Did you bring food?, (yes or No)").toLowerCase();
        if(hungry === 'yes' && food === 'yes') {
            console.log("Let's eat!");
        } else (hungry === 'yes' && food === 'no') {
            console.log("Go get us some food!");
        }
    
        break;
    case 'Ray':
        var cook = prompt("Hey Dude, Can you cook? (Yes or No)").toLowerCase();
        var have = prompt("Do have any food? (Yes or No)").toLowerCase();
        if(cook === 'yes' && have === 'yes') {
            console.log("Great! you can fix diner!");
        } else (cook === 'no' || have === 'no') {
            console.log("Thats ok I can fix something to eat");
        } 
        break;
    case 'Marcela':
        console.log("What's for dinner?");
        break;
    default:
        console.log("We starve");
}


#2

Hi the else statement doesn't take any condition

if (condition) {
   #do something
}
else {

}

so you should remove the condition to all your else statement


#3

Thank you, it worked


#4

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