Logical operators


#1


Hey, when i input 5 and 5 i still get the else if output and not the else output. What am i doing wrong ?
hope u guys can help me :slight_smile:


var user = prompt("Are you ready to gith the goblin king ?").toUpperCase();
var power = prompt("How much power do u have ? (1-5)").toUpperCase();
var health = prompt("How much health do u have ? (1-5)").toUpperCase();

switch(user){
    case 'YES':
        if(power<=3 && health<=3){
            console.log("you are to weak and lose the fight");
        }
        else if (power>=4 || health>=4){
            console.log("u almost got killed but made it");
        }
        else{
        console.log("u nailed it !");
        }
        break;
    case 'No' :
        console.log("you run away");
        break;
    default:
        console.log("We can't do that right now");
        break;
    
}


#2

In your else if statement, your checking to see if power and health are greater than or equal to 4, which they are when you input 5.
Try changing this:

else if (power>=4 || health>=4)

To this:

else if (power<=4 || health<=4)

#3

Ya but i want to check if "power" or "health" is 4 or higher. so only one of the two,

for example :
2 power and 1 health = if output
5 power and 3 health = else if output
2 power and 4 health = else if output
4 power 5 health = else output
5 power 5 health = else output.


#4

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