Advertisement
Neri0817

Untitled

Feb 15th, 2022
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pig(input) {
  2.   let food = Number(input[0]) * 1000;
  3.   let hay = Number(input[1]) * 1000;
  4.   let cover = Number(input[2]) * 1000;
  5.  
  6.   let guineaKG = Number(input[3]) * 1000;
  7.   let days = 30;
  8.  
  9.   for (index = 1; index <= days; index++) {
  10.     food -= 300;
  11.  
  12.     if (food <= 0) {
  13.       break;
  14.     }
  15.     if (food > 0) {
  16.       if (index % 2 === 0) {
  17.         hay -= food * 0.05;
  18.         if (hay <= 0) {
  19.           break;
  20.         }
  21.       }
  22.       if (index % 3 === 0) {
  23.         cover -= guineaKG / 3;
  24.         if (cover <= 0) {
  25.           break;
  26.         }
  27.       }
  28.     }
  29.   }
  30.  
  31.   if (food <= 0 || hay <= 0 || cover <= 0) {  // проврката
  32.     console.log("Merry must go to the pet store!");
  33.   } else {
  34.     console.log(
  35.       `Everything is fine! Puppy is happy! Food: ${(food / 1000).toFixed(
  36.         2
  37.       )}, Hay: ${(hay / 1000).toFixed(2)}, Cover: ${(cover / 1000).toFixed(2)}.`
  38.     );
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement