Logical Operators - Only else statements being output?


#1

I am able to pass the lesson, but I am frustrated to see that my code will only output the "else" statements for each entry, no matter what I input. I feel like I must have something wrong with my logical operators.

Does anyone know why this might be happening?

I appreciate any insight you can offer. Thank you for your time! 🙏🏻😊


var user = prompt("Let's go to Seattle! What's the first thing you want to see when you get there: Space Needle, Pike Place or Mt. Rainier?").toUpperCase();

switch (user) {
case 'SPACE NEEDLE':
var top = prompt("Are you scared to go to the top?");
var beer = prompt("Will you have a local brew once you get there?");
if (top === 'YES' && beer === 'YES') {
console.log("Let's get tipsy on top of Seattle and post to Insta!");
} else {
console.log("Maybe we should go to a sea-level bar instead!");
}
break;
case 'PIKE PLACE':
var coffee = prompt("Will you visit the first Starbucks?");
var doughnuts = prompt("Will you eat the mini doughnuts?");
if (coffee === 'YES' || doughnuts === 'YES') {
console.log("Yum. Authentic Seattle!");
} else {
console.log("You're going to miss out!");
}
break;
case 'MT. RAINIER':
var hike = prompt("Will you hike to the top?");
var experience = prompt("Have you done this before?");
if (hike === 'YES' && experience === 'YES') {
console.log("Phew. For a minute there I was scared!");
} else {
console.log("I'm not sure this is such a good idea...");
}
break;
default:
console.log("What an exotic choice! Save me a seat on the bus!");
break;
};


#2

Your code looks good. But you forgot to add the .toUpperCase() for your prompts after your case.

I think there's a glitch with this lesson b/c I got the output by "else" statements for the first case only. The other two cases works fine but the "space needle" case has a glitch. I tried the "or" operator instead of "and" operator and that seems to fix it. Like so:

switch(user) {
case 'SPACE NEEDLE':
var top = prompt("Are you scared to go to the top?").toUpperCase();
var beer = prompt("Will you have a local brew once you get there?").toUpperCase();
if(top === 'YES' || beer === 'YES') {
console.log("Let's get tipsy on top of Seattle and post to Insta!");
} else {
console.log("Maybe we should go to a sea-level bar instead!");
}
break;

I don't think it's your code. Either something's wrong with this lesson or we're both doing it wrong


#3

Thank you so much for looking at my code. I had .toUpperCase(); on all of the prompts but had removed them thinking that maybe that was the issue before. Doesn't seem to effect anything whether it is there or not.

Thank you for your solution but I tried to run the code again having switched the && to || and I still get the else statement, so it isn't working for me. It's a relief to know that's it's likely a glitch, after spending a few hours trying to figure it out!