Code your own adventure 2 5/6


#1

var user = prompt("What's your name?").toLowerCase();

switch(user) {
case 'alfre':
var alfresAnswer = prompt("So you're he who is called the creator.").toLowerCase()

    if(alfresAnswer === "yes"||"sure") {
        console.log("Welcome master")
    } else {
        console.log("Oh you look alike")
    }
    break;

case 'carlos':
    console.log("So you are the creator's brother");
    break;

case 'felipe':
   var felipesAnswer = prompt("The guy with the glasses huh?").toLowerCase();

   if (felipesAnswer === "yes") {
       console.log("Oh, very nice")
   } else if ("no") {

       var secondAnswer = prompt("What do you do in life? School, sports or/and music?").toLowerCase()
       if (secondAnswer === "school and "&&"sports") {
           console.log("Nice Mr. Pipio")
       } else {
           console.log("I dont like lying Mr Pipe")
   }
    }
    break;

default:
console.log("Nice name");

};

I dont understand why when I chose "felipe", "no", and then "school and sports" it always ends printing out "I don't like lying mr pipe". I type the answer exactly "school and sports", the alfre one works properly though so I don't know what could it be happening with the pipe one. Thanks for the help.


#2

@alfre360 where you have:

 } else if ("no") {

you need to make a comparison, ie. else if (variable === "no") since this is from an if statement rather than a case statement.


#3

This condition can't work. The 2nd part of the condition ('sports') isn't compared to anything. Therefore it is evaluted as TRUE.

And by the way, a variable can only store 1 value. So you can't even make a condition like

if (secondAnswer === "school and "&&secondAnswer=== "sports")

because the variable can only store the value "school and" or the value "sports". However you could make a condition that checks if one of the following was entered: "school", "school and sports", "sports".

if(secondAnswer=== "school" || secondAnswer==="school and sports" || secondAnswer==="sports") {


#4

Thanks for the info it really helps :+1:


#5

var user = prompt("how are you feeling today?").toUpperCase();

switch(user) {
case 'cranky':
console.log("that is not good to know");
var user1 = true;
var user2 = true;
if(user1 && user2) {
console.log("nice!"); }
else { console.log("bad choice!"); }
break;
case 'awesome':
console.log("i wonder what did you eat today?");
var user1 = true;
var user2 = true;
if(user1 || user2) {
console.log("wow!"); }
else { console.log("boooo"); }
break;
case 'sad':
break;
console.log("eat a candy bar");
break;
default:
console.log("How would you like a massage?" + user + "!");
}

here is mine, which ran good. I hope it helps you


#6

Thank you!!! I've been lost for the last three hours. Makes sense now!