I tried to convert these if statement to ternary:
var eatsPlants = false;
var eatsAnimals = true;
if(eatsPlants){
return 'herbivore';
}else if(eatsAnimals){
return 'carnivore';
}else if(eatsPlants && eatsAnimals){
return 'omnivore';
}else{
return undefined;
}
Here's my solution:
var category = eatsPlants && eatsAnimals ? "omnivore" : "herbivore" : "carnivore" : undefined;
console.log(category);
But this doesnt work and it returns the error missing semicolon.
Any idea how to fix it?
You should add the remaining if
conditions too
var category = eatsPlants && eatsAnimals ? "omnivore" : eatsPlants? "herbivore" : eatsAnimals? "carnivore" : undefined;
console.log(category);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments