5. Logical Operators: I simply don't understand how to apply this lesson to my game


#1

var user = prompt("You are drifting through a familiar dream when you hear your name being called by strange voices through a floating door. Do you GO IN, RUN AWAY or CALL OUT to them?").toUpperCase();
switch(user) {
case 'go in':
console.log("Woah... it's bright in here. Are those.. stars? They're blue and they're talking to you.");
break;
case 'run away':
console.log("Too scared yet, my friend? You may be able to run but the voices do not stop. It's time to plan your next move.");
break;
case 'call out':
console.log("The voices go silent. They hear you but you are not close enough for them to express what they must tell to you.");
break;
default:
console.log("Woah now, you've disappeared. Where did you go?");
}

This is my code so far. I have not added an if/else statement inside any case because I am having trouble figuring out how this actually works? Am I creating new variables? The instructions say "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."

How would I check if two conditions are or aren't true if the user can only respond with one answer? I think I am missing the logic in this lesson. Any help is appreciated. :disappointed_relieved:


#2

@marleemaloy,
You could ask for more information

var strong = prompt("Are feeling strong yes/no","yes").toLowerCase();
var favColor = prompt("What is your favorite color","red").toUpperCase();
var user = prompt("You are drifting through a familiar dream "+
                  "when you hear your name being called by strange voices "+
                  "through a floating door. "+
              "Do you GO IN, RUN AWAY or CALL OUT to them?").toUpperCase();
switch(user) {
 case 'GO IN':
     if ( strong === "yes" && favColor === "red" ) {
        console.log("I wish you all the best !!");
     }
     else {
        console.log("You are going to get a hard time.....");
     }  
    console.log("Woah... it's bright in here. Are those.. stars? They're blue and they're talking to you.");
    break;
 case 'RUN AWAY':
     if ( strong === "yes" || favColor === "red" ) {
       console.log("It is a pity, that you run away as you were strong or red");
     }
     console.log("Too scared yet, my friend? "+"\nYou may be able to run but the voices do not stop."+
     " \nIt's time to plan your next move.");
    break;
 case 'call out':
 console.log("The voices go silent. They hear you but you are not close enough for them to express what they must tell to you.");
 break;
 default:
 console.log("Woah now, you've disappeared. Where did you go?");
}

#3

@leonhard.wettengmx.n Ahhh, I see. Thank you very much for this, I will work on this further tonight, as I am going to class right now, but I wanted to thank you for your response!


#4

Thank you @leonhard.wettengmx.n. I was wondering the same thing when I got to this section.


#5

I also thank you. I knew that I could ask for more information, but was stumped on what to ask or how exactly I should approach it considering the question I'd posed, so I came here looking for ideas. This helped a lot.