Advertisement
Spocoman

03. Animal Type

Dec 19th, 2021 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function animalType(animal) {
  2.  
  3.     if (animal == "dog")
  4.         console.log("mammal");
  5.     else if (animal == "crocodile" || animal == "tortoise" || animal == "snake")
  6.         console.log("reptile");
  7.     else
  8.         console.log("unknown");
  9. }
  10.  
  11. Второ решение(switch):
  12.  
  13. function animalType(input) {
  14.     let animal = input[0];
  15.  
  16.     switch (animal) {
  17.         case "dog":
  18.             console.log("mammal");
  19.             break;
  20.         case "crocodile":
  21.         case "tortoise":
  22.         case "snake":
  23.             console.log("reptile");
  24.             break;
  25.         default:
  26.             console.log("unknown");
  27.             break;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement