10/6 Code your own adventure!


#1

Hello everyone,

So my code works, but the OR operation under 'Oatmeal' is giving me the first response for console, no matter the answer. I could enter 'no' for both and it shouldn't write the if response, it should write the else response.

var user = prompt("What is your favorite food for breakfast?").toLowerCase();

switch(user){
case 'cereal':
console.log("Ah cereal, the breakfast of champions!");
break;
case 'eggs':
console.log("Eggs are high in protein, nice choice!");
var eggs = prompt("How many eggs?");
var toast = prompt("Any toast?");

    if(eggs > 1 && toast === 'yes') {
        console.log("I always eat toast with breakfast and more than 1 egg!");
    }
    else{
        console.log("Eggs and no toast is not a lot for breakfast");
    }
    break;
case 'oatmeal':
    console.log("Oatmeal is a classic, yum!");

     var fruit = prompt("Do you like fruit in your oatmeal?");
     var honey = prompt("Do you add honey?");

     if(fruit || honey === 'yes') {
         console.log("I love adding toppings to my oatmeal!");
     }
     else{
         console.log("BORING!!!");
     }
    break;
case 'smoothie':
    console.log("Fruit smoothies are delicious!");
    break;
default:
    console.log("I guess you don't eat breakfast?");

}


#2

Ok, I was able to figure it out -

I changed if(fruit || honey === 'yes') to if(fruit === 'yes' || honey === 'yes')

When you do && it doesn't require both, is this different for || ?