Code your own adventure 2 - 5. Logical Operatos


#1


https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#

Hi everyone, I passed the cases, but cannot understand why case "independence day" will not go to my ELSE statement. Any advice is appreciated

Replace this line with your code. 
var user = prompt("What is your favorite movie?").toUpperCase();

switch(user)
{
//ignore TOTAL RECALL
  case 'TOTAL RECALL':
    var actor = prompt("Isn't Arnold the BEST?").toUpperCase();
    var governor = prompt("Is he a better actor or governor").toUpperCase();
    if(actor === 'YES' &&  governor === 'ACTOR')
    {
      console.log ("Yeah, i hear you");
    }else{
      console.log("HAH! I disagree");
    }
    break;
    
    case 'INDEPENDENCE DAY':
    var character = prompt("Who's best: Bill Paxton, Will Smith or Jeff Goldblume?").toUpperCase();
    if(character === 'BILL PAXTON'||'WILL SMITH')
    {
// this case consistently says "Those 2 were the best!"
      console.log ("Those 2 were the best!");
    }else{
      console.log("Jeff Goldblum was trash!");
    }
    break;
    
  default:
    console.log("I haven't seen that one");
}


#2

because the if condition is always true.

strings are considered true, for example:

if('this is true'){
  console.log("i will always run");
} else {
  console.log("i will never run");
}

your or comparison is not good, on both sides you have to compare with character:

if(character === 'BILL PAXTON'|| character === 'WILL SMITH')

#3

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