Logical operators


#1

Whatever 'case' i put in the promppt it always has the same outcome in the result tab.The default
Code:

var user = prompt("What's your name?").toUpperCase();
switch(user) {
    case 'Thanasis':
        console.log("That's a great name");
        var pseudo = prompt("How do your friends call you?").toLowerCase();
        if (pseudo === "MALAKA" || "SAKIS") {
            console.log("Mine too");
        } else {
            console.log("That's nice");
        }
        break;
        case'John':
            console.log("That's my best friend's name");
            var nickname = prompt("What's your nickname?").toLowerCase();
            if (nickname === "GIANNARE" && "MEGALE") {
                console.log("Two nicknames huh?Nice");
            } else {
                console.log("Awesome");
            }
            break;
            case'Petros':
                console.log("That's my other best friend's name");
                break;
                default:
                console.log("No name?AAright.");
}

#2

Your cases have lower case letters. You've converted all the letters to upper case, so they won't match.


#3

I changed everything.Same outcome


#4

That tells me nearly nothing!

Look at your code. user refers to a string which is all upper case. Anything that's to match it also has to be upper case, alternatively user shouldn't be made all upper case. So, you'll have to consider what values user is compared to, and adjust those.


#5

Same outcome..Different codThis is my code

switch(user) {
    case 'Thanasis':
        console.log("That's a great name");
        var pseudo = prompt("How do your friends call you?").toUpperCase();
        if (pseudo === "Malaka" || "Saki") {
            console.log("Mine too");
        } else {
            console.log("That's nice");
        }
        break;
        case'John':
            console.log("That's my best friend's name");
            var nickname = prompt("What's your nickname?").toUpperCase();
            if (nickname === "Giannare" && "Megale") {
                console.log("Two nicknames huh?Nice");
            } else {
                console.log("Awesome");
            }
            break;
            case'Petros':
                console.log("That's my other best friend's name");
                break;
                default:
                console.log("No name?AAright.");
}

#6

If you're still converting user to upper case, then note that you still have lower case letters in the cases.


#8

Ok i change my 'cases' letters to upper case.But why is that?Shouldn't be just the first letter an upper case?


#9

What does a switch do?

If we know how a switch works, then we can figure out how to use it. So how does user relate to the cases?


#10

Kinda understood.Not fully though.Thanks


#11

Cases have to match exactly. If the value to be matche is all upper case, then so do the cases have to be.


#12

Thanks for your time