5 Logical operators! my else does not work


#1

Ok! so my if function works perfectly but the ELSE does not work at all! Thank you in advance, this is my code!

var user = prompt("Who do you pefere between", "Perez, Vico and Zach?").toUpperCase();
switch (user) {
    case 'PEREZ':
        var crush = prompt("Confam you make sense", "will you ever date him? Yes or No?").toUpperCase();
        var funny = prompt("Do you think he is funny?", "Yes or No -_- ?").toUpperCase();
        if (crush || funny === "YES") {
            console.log("You try, Perez gets more girls than zack and vico combined");
        } else {
            console.log("Thunder Fire your left Nyash");
        }
        break;

    case 'VICO':
        var beard = prompt("Lol do you like guys with beards?").toUpperCase();
        var fine = prompt("Lol! do you really think vico is finer than Perez?").toUpperCase();
        if (beard && fine === "YES") {
            console.log("Don't ever play your self");
        } else {
            console.log("Lol! clap for yourself!");
        }
        break;
    case 'ZACH':
        console.log("You Have not learnt from kaylor abi?");
        break;
    default:
        console.log("Dont give a stupid answer")
}

#2

It is not clear what you mean by: "but the ELSE does not work at all". However, I think the problem is here:

if (crush || funny === "YES") { // conditional A

should be:

if (crush === "YES" || funny === "YES") {

This is because your conditional A is interpreted as: Either point 1 or 2 is true

  1. crush
  2. funny === "YES"

If crush is a non-empty string, then it will always be true (non-empty strings coerce to true in JS) That's the most probable reason I can see why your else branch doesn't execute.

Similar treatment for if (beard && fine === "YES") {.


#3

oh men! Thanks alot! I really appreciate sir!