Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created August 27, 2017 14:59
Show Gist options
  • Save prof3ssorSt3v3/a3e1fb852840a6caba2bcd652693599c to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/a3e1fb852840a6caba2bcd652693599c to your computer and use it in GitHub Desktop.
// Binary Logical Operators
// AND &&
// OR ||
// creating compound if statements
let ingredients = ['ham', 'onion', 'tomato'];
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('onion') ){
console.log('it has both')
}else{
console.log('it has NOT both but maybe one of them')
}
if( (sandwichHas('cheddar') && sandwichHas('onion')) ||
sandwichHas('onion') && sandwichHas('tomato')){
console.log('cheese and lettuce ... OR onion')
}else{
console.log('failed final test')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment