Logical Operators AND and OR
Video
JavaScript Notes
JavaScript
// Binary & Logical Operators
// AND &&
// OR ||
// creating compound if statements
let ingredients = ['lettuce', 'cheddar', 'ham'];
let sandwichHas = function(ingredient){ for(let i of ingredients) {
if( i == ingredient) {
return true;
}
}
return false;
// if this line omitted it returns undefined
// which is also a falsey value
if (sandwichHas('ham') || sandwichHas('chicken') || sandwichHas('beef') ){
console.log('Sandwich has meat')
} else {
}
console.log('No meat')
if (sandwichHas('lettuce') && sandwichHas('tomato') ){
console.log('It has both')
} else {
console.log('It has NOT both but maybe one of them')
}
Feedback
Submit and view feedback