Advertisement
Spocoman

Cat Life

Jan 7th, 2022
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function catLife(input) {
  2.     let catBreed = input[0];
  3.     let catGender = input[1];
  4.  
  5.     let breedYears = 0;
  6.  
  7.     switch (catBreed) {
  8.         case "British Shorthair":
  9.             breedYears = 13;
  10.             break;
  11.         case "Siamese":
  12.             breedYears = 15;
  13.             break;
  14.         case "Persian":
  15.             breedYears = 14;
  16.             break;
  17.         case "Ragdoll":
  18.             breedYears = 16;
  19.             break;
  20.         case "American Shorthair":
  21.             breedYears = 12;
  22.             break;
  23.         case "Siberian":
  24.             breedYears = 11;
  25.             break;
  26.         default:
  27.             console.log(`${catBreed} is invalid cat!`);
  28.             break;
  29.     }
  30.  
  31.     if (catGender === "f") {
  32.         breedYears++;
  33.     }
  34.  
  35.     if (breedYears > 1) {
  36.         console.log(`${breedYears * 2} cat months`);
  37.     }
  38. }
  39.  
  40.  
  41.  
  42. Фундаменталс решение:
  43.  
  44. function catLife([catBreed, catGender]) {
  45.  
  46.     let breedYears = {
  47.         "Siberian": 11,
  48.         "American Shorthair": 12,
  49.         "British Shorthair": 13,
  50.         "Persian": 14,
  51.         "Siamese": 15,
  52.         "Ragdoll": 16
  53.     }[catBreed];
  54.  
  55.     catGender === "f" ? breedYears++ : breedYears;
  56.  
  57.     console.log(breedYears > 1 ? `${breedYears * 2} cat months` : `${catBreed} is invalid cat!`);
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement