Can someone please tell me why... #5 (code own adventure) Question


#1

Question asks " is you're name Adele, Heidi, or Sylvia?" Can any one please tell me why when I type in Sylvia, and then it asks "Are you Sylvia?" type in "Yes" and then it says "Sorry, your not sylvia" When it should be saying"Hi, Sylvia!" after typing in yes??????
After typing in No is when it should be saying "sorry your not Sylvia."

Same for Adele.

When I type "Yes" in for "Heidi" nothing comes up on the screen..

Got a green check I'm just very confused why it's doing this.

var user = prompt("Hello! Is your name Adele, Heidi, or Sylvia?");

switch(user) {
case 'Adele':
var Adele = prompt("Are you Adele?");
if(user == "yes" || user == "no") {
console.log("Hi Adele!");
}
else {
console.log("Sorry, you're not Adele.");
}
break;

case 'Heidi':
    var Heidi = prompt("Are you Heidi?");
    if(user == "yes" || user == "no") {
    console.log("Hi, Heidi!");

    }
    break;

case 'Sylvia':
    var Sylvia = prompt("Are you Sylvia?");
    if(user ="yes" && user == "no") {
    console.log("Hi, Sylvia!");
    }
    else {
        console.log("Sorry, you're not Sylvia.");
    }
    break;
default:
    console.log("Sorry, that name is not recognized.");

}


#2

see your code

case 'Sylvia':
var Sylvia = prompt("Are you Sylvia?");
if(user ="yes" && user == "no") {
console.log("Hi, Sylvia!");
}
else {
console.log("Sorry, you're not Sylvia.");
}
break;

when you type Sylvia.Then it'll ask Are you Sylvia? now see your code if user="yes" && user="no"
is it right? the value yes or no will be store in Sylvia variable.but you are checking user.ok? now think how could it be possible user="yes" && user="no" ?? you should check if yes then somthing if no then somthing else.(according to what you want).

hope u'll understand now :slight_smile:


#3

yes thankyou! I added
var Sylvia = prompt("Are you Sylvia?, (yes or no)");
and it worked! :))))


#4

correction:
it works with sylvia when it's
if(sylvia ==="yes" || Sylvia == "no")

it doesn't work when && is used. But I think I understand now.


#5

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