-
-
Save desinas/907ac97e97223030721c248879c52e79 to your computer and use it in GitHub Desktop.
The format of the conditionals I suggest is this:
var category = 🌿&🐮 ? "omnivore" : (🐮? "carnivore" : (🌿 ? "herbivore" : undefined ) );
So that, to check for the category in all options.
/*
//Please help me
//In this exercise .. I am a beginner
//
- 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
eatsPlantsandeatsAnimalsin your ternary expressions
- use the variables
-
ifstatements aren't allowed ;-)
*/
/*
- QUIZ REQUIREMENTS
-
- Your code should have the variables
eatsPlants,eatsAnimals
- Your code should have the variables
-
- 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.
*/
- 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)
*/
- (false, false, undefined)
var category = /* your code goes here */
console.log(category);
var category = eatsPlants && eatsAnimals ? "omnivore" : ( eatsAnimals ? "carnivore" : ( eatsPlants ? "herbivore" : undefined ) );
var eatsPlants = false;
var eatsAnimals = false;
var category = eatsPlants && eatsAnimals ? "omnivore" : ( eatsAnimals ? "carnivore" : ( eatsPlants ? "herbivore" : "undefined" ) );
console.log(category);
var eatsPlants = false;
var eatsAnimals = false;
var category = (eatsPlants && eatsAnimals) ? "omnivore": (!eatsPlants && eatsAnimals) ? "carnivore" : (eatsPlants && !eatsAnimals) ? "herbivore" : (!eatsPlants && !eatsAnimals) ? "undefined": undefined
console.log(category);
What Went Well
Feedback: Your answer passed all our tests! Awesome job!