Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /*
  2. * Programming Quiz - Navigating the Food Chain (3-8)
  3. *
  4. * Use a series of ternary operator to set the category to one of the following:
  5. * - "herbivore" if an animal eats plants
  6. * - "carnivore" if an animal eats animals
  7. * - "omnivore" if an animal eats plants and animals
  8. * - undefined if an animal doesn't eat plants or animals
  9. *
  10. * Notes
  11. * - use the variables `eatsPlants` and `eatsAnimals` in your ternary expressions
  12. * - `if` statements aren't allowed ;-)
  13. */
  14.  
  15. // change the values of `eatsPlants` and `eatsAnimals` to test your code
  16. var eatsPlants = true;
  17. var eatsAnimals = false;
  18.  
  19. var category = (eatsPlants && eatsAnimals) ? "omnivore" : ( eatsPlants ? "herbivore": ( eatsAnimals ? "carnivore" : undefined ) );
  20.  
  21. console.log(category);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement