I know this is common but I’m confused. Can someone explain what’s the problem with my condition? The result below should reflect the else statement since the value of extension is ‘Sr.’
var extension = "Sr.";
if (extension != "Jr." || extension != "Sr." || extension != "I") {
console.log("Should be false"); // the result goes here in if statement
} else {
console.log("Should be True");
}
The result of the code above is false it should be true
2
Answers
Well you should read again about logic table
(extension !="Jr." || extension !="Sr." || extension !="I") <== that mean if result one of these is true (match as result in above case it will return false if equal to extention value) than the else statement will be execute
Change OR (||) to AND (&&) so all condition are meet with the case.
you should use "AND"(&&) statement to get your required output.
This will go into else block if the extension is any of (Jr, Sr, I).