Liliana797979

viarno reshenie puppy and merry - mid exam

Jul 19th, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2. function puppy(input) {
  3.  
  4.     let food = Number(input[0]) * 1000;
  5.     let hay = Number(input[1]) * 1000;
  6.     let cover = Number(input[2]) * 1000;
  7.     let weight = Number(input[3]) * 1000;
  8.     let IsNeedsFullfiled = true;
  9.  
  10.  
  11.     for (let i = 1; i <= 30; i++) {
  12.  
  13.         food -= 300;
  14.         if (food <= 0) {
  15.             IsNeedsFullfiled = false;
  16.             break;
  17.         }
  18.  
  19.         if (i % 2 == 0) {
  20.             hay = hay - (food * 0.05);
  21.             if (hay <= 0) {
  22.                 IsNeedsFullfiled = false;
  23.                 break;
  24.             }
  25.  
  26.         }
  27.         if (i % 3 == 0) {
  28.             cover = cover - (weight / 3);
  29.  
  30.             if (cover <= 0) {
  31.                 IsNeedsFullfiled = false;
  32.                 break;
  33.             }
  34.         }
  35.  
  36.     }
  37.  
  38.     if (IsNeedsFullfiled) {
  39.         console.log(`Everything is fine! Puppy is happy! Food: ${(food / 1000).toFixed(2)}, Hay: ${(hay / 1000).toFixed(2)}, Cover: ${(cover / 1000).toFixed(2)}.`);
  40.     } else {
  41.         console.log(`Merry must go to the pet store!`);
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment