Logical Operators No syntax error, only returning for default


#1


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


There is no error message, but it only returns for default.


var user = prompt("what's your name?").toUpperCase();
switch (user){
    case'JENNIFER':
    if (user || "JENNY","JEN") {
        console.log("I'd shorten that too!"         );
        }
        else {
            console.log("I love that name!"); }
    break;
    
    case'MELISSA':
    if (user && "MISSY") {
    console.log("Have you ever traveled through time");
    }
    else {
        console.log("That's a really cool name");
    }
    break;
    
    case'LISANNE':
    console.log("That's an awesome name");
    break;
    
    default:
        console.log("I've never heard that name before. It's pretty.");
    
}


#2

can you tell me what do you want to do if case is 'JENNIFER' or 'MELISSA' ?
what are you trying to do in following line?

if (user || "JENNY","JEN") {


#3

I was trying to give an alternate answer option for each with it's own log reply

So, in the case of Jennifer, if they say Jenny or Jen that would be understood to have the same name with a slightly different reply. Same thing with Melissa.


#4

First of all just think what you've write in your code.

case'JENNIFER':

so here if case JENNIFER is true then it'll go through the case.so if case is true it simply means user is JENNIFER it'll never be "JENNY" or "JEN" .so it doesn't make sense to check because you already know user is 'JENNIFER' and if user is "JENNY" or "JEN" then it simply means your case is false.

now here

if (user || "JENNY","JEN") {

you can't check like this.it'll always be true.you have to check both side like

if (user=="JENNY" || user=="JEN") {


#5

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