5. logical operators - dont understand what to do!


#1


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

hi everyone im just confused because it says to:
'Add some if/else statements to your cases that check to see whether one condition and another condition are true, as well as whether one condition or another condition are true. Use && and || at least one time each.'

im just unsure of what to do because i dont know where the if/else bits would go. i just cant see any room or need for them in my code. ive looked at other peoples threads on here about what they did and people seemed to have put them in very different places.

here is my code. excuse the dorky strings, im just messing around

var user = prompt("Would you like to stay in my hotel? \
YES/NO/MAYBE").toUpperCase();

switch(user) {
    
    case "YES":
        console.log("They beckon you inside.");
        break;
    case "NO":
        console.log("Thunder rumbles. Shutters rattle on the\
        nearby window. The smell of bread wafts from the inn.");
        break;
    case "MAYBE":
        console.log("Yes or no? We don't want any time wasters,\
        taking up time we could be spending on other\ customers");
        break;
    default:
        console.log("'Do you want to stay? Yes or no?' says\
        the host. 'We don't want any time wasters.'");
        break;
}

does it go within the cases? or after? i think ive seen people do both in the forums but maybe im misunderstanding


#2

@oonmw,
Just create 2 IF statement's in 2 different CASE's
making up condition's
like
( 10< 11 && 3 >2)
( 12<14 || false)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators


#3

I put mine after the "case 'choice' :" and before the console.log assigned to the corresponding case. Post your new code so we can see what you ended up trying.


#4

I did it by adding variables under my case, then building on those variables with an if/else statement.

For you, under case "YES", you can add:

var sexyHotel = prompt("Would you like a lover's suite?");
var lover = prompt("Will anyone be joining you?");
if(sexyHotel === 'YES' && lover === 'yes'){
console.log("You are going to have a fun stay here!")
} else {
console.log("Well, have fun anyways!")
};


#5

@biff75 i ended up just doing:

var user = prompt("Would you like to stay in my hotel? \
YES/NO/MAYBE").toUpperCase();

switch(user) {
    
    case "YES":
        var fear = prompt("This place makes your skin\
        crawl. Are you sure?").toUpperCase();
        if (fear === "YES" && 8>1){
        console.log("The host's face darkens. \
        They beckon you inside.");
        } else {
        console.log("You stammer out that actually\
        you had better be off.");
        }
        break;
    case "NO":
        var cold = prompt("The host says that it's a \
        shame. The lovely hot soup should be just about\
        ready to eat now.\
        Sure you don't want to stay and have a bowl, \
        on the house?").toUpperCase();
        if (cold === "YES" || cold === "Y") {
        console.log("Thunder rumbles. Shutters rattle on the\
        nearby window. The smell of bread wafts from inside.");
        } else {
            console.log("You shrug and step inside at\
            the kind offer.");
        }
        break;
    case "MAYBE":
        console.log("Yes or no? We don't want any time \               wasters, taking up time we could be spending on other\ customers");
        break;
    default:
        console.log("'Do you want to stay? Yes or no?' says\
        the host. 'We don't want any time wasters.'");
        break;
}

thanks you guys, it was very helpful. the logical operators are kind of pointless and arbitrary, just because it says you have to use them. @karenafrye hah the way you used them makes a lot more sense but it works and i get it so im happy


#6

Thank you so much :smile: