-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[Ternary operator]Navigating the Food Chain (3-8)
43 lines (33 loc) · 1.33 KB
/
[Ternary operator]Navigating the Food Chain (3-8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* 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 ;-)
*/
/*
* QUIZ REQUIREMENTS
* - Your code should have the variables `eatsPlants`, `eatsAnimals`
* - Your code should include ternary statements. Do not use if....else statement.
* - Your code should produce the expected output
* - Your code should not be empty
* - BE CAREFUL ABOUT THE PUNCTUATION AND THE EXACT WORDS TO BE PRINTED.
*/
// change the values of `eatsPlants` and `eatsAnimals` to test your code
var eatsPlants = false;
var eatsAnimals = true;
/*
* Test your code agaist the followig possible input/output combinations of (`eatsPlants`, `eatsAnimals`, expected output):
* - (true, true, omnivore)
* - (false, true, carnivore)
* - (true, false, herbivore)
* - (false, false, undefined)
*/
var category = eatsPlants && eatsAnimals ? "omnivore" : (eatsPlants? "herbivore" : (eatsAnimals? "carnivore" : "undefined"));
console.log(category);