Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 = false;
  17. var eatsAnimals = false;
  18.  
  19. var category = (eatsPlants === true && eatsAnimals === true) ? "omnivore":
  20.                 (eatsPlants === true && eatsAnimals === false) ? "herbivore":
  21.                 (eatsPlants === false && eatsAnimals === true) ? "carnivore":
  22.                 "undefined";
  23.  
  24.  
  25.  
  26. console.log(category);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement