Need help! 5. Logical operators


#1

Hi guys! Here's my code:

var user = prompt("It's an ordinary day, but you come across a villain tearing apart the city! You have enough battery on your phone to call one superhero. Which one will you pick? SUPERMAN, BATMAN, or THE FLASH?").toUpperCase();

switch(user) {
case 'SUPERMAN':
console.log("Nice!");
var choice = prompt("Which of his powers do you think he'll use? SUPER STRENGTH or HEAT VISION?").toUpperCase();
if (choice = SUPER STRENGTH || choice = HEAT VISION) { console.log("Let's see him in action!");
} else { console.log("Not sure what you're talking about."); }
break;
case 'BATMAN':
console.log("It might work.");
var choice = prompt("Which gadgets do you advise he should use? BATARANG OR BATCLAW?").toUpperCase();
if (choice = BATARANG && choice = BATCLAW) {
console.log("I think he'll use that too.");
} else { console.log("You don't know much about Batman!"); }
break;
case 'THE FLASH':
console.log("That was a quick one!");
var choice = prompt("Will he get it done in a flash? YES or NO?").toLowerCase();
if (choice = YES) { console.log("You got the joke!");
} else { console.log("Bummer."); }
break;
default:
console.log("Are you sure about your choice?");
}

It keeps saying 'Oops, try again. There was a problem with your syntax.' I'm sure what's wrong here. Help!!


#2

Well, I don't see anything as of yet that would cause a syntax error other than under...

var choice = prompt("Will he get it done in a flash? YES or NO?").toLowerCase();
if (choice = YES) { console.log("You got the joke!");

you use toLowerCase instead of toUpperCase, and you call "YES" in upper case.


#3

I tried this edit, and I got the message "Unexpected identifier 'STRENGTH'". I still have no ideas... Could you look at my post "No ideas 5/6"? Thx
jrpsychgal


#4

I changed it to toUpperCase, but it still says 'SyntaxError: Unexpected identifier'. Maybe there is a variable I need to define or something.


#5

Found the answer! Instead of:
if (choice = SUPER STRENGTH || choice = HEAT VISION)

it should be:
if (choice === 'SUPER STRENGTH' || choice === 'HEAT VISION)


#6

Oh! That makes total sense. Why didn't I spot that? :confused: :confused: :confused: :sweat_smile: