Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function animalType(animal) {
- if (animal == "dog")
- console.log("mammal");
- else if (animal == "crocodile" || animal == "tortoise" || animal == "snake")
- console.log("reptile");
- else
- console.log("unknown");
- }
- Второ решение(switch):
- function animalType(input) {
- let animal = input[0];
- switch (animal) {
- case "dog":
- console.log("mammal");
- break;
- case "crocodile":
- case "tortoise":
- case "snake":
- console.log("reptile");
- break;
- default:
- console.log("unknown");
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement