A Pen by ClaudiaInBytes on CodePen.
Created
August 20, 2017 20:54
-
-
Save claudiainbytes/52a3ab1e82c4f89effa5b8bc890bb9e9 to your computer and use it in GitHub Desktop.
The Food Chain - Ternary Operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Programming Quiz - Navigating the Food Chain (3-8) | |
* | |
* Use a series of ternary operator to set the category to one of the following: | |
* - "herbivore" if an animal eats plants | |
* - "carnivore" if an animal eats animals | |
* - "omnivore" if an animal eats plants and animals | |
* - undefined if an animal doesn't eat plants or animals | |
* | |
* Notes | |
* - use the variables `eatsPlants` and `eatsAnimals` in your ternary expressions | |
* - `if` statements aren't allowed ;-) | |
*/ | |
// change the values of `eatsPlants` and `eatsAnimals` to test your code | |
var eatsPlants = true; | |
var eatsAnimals = false; | |
var category = (eatsPlants && eatsAnimals) ? "omnivore" : ( eatsPlants ? "herbivore": ( eatsAnimals ? "carnivore" : undefined ) ); | |
console.log(category); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment