Advertisement
Neri0817

01. Guinea Pig

Feb 15th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function guineaPig(array) {
  2.   let gram = 1000;
  3.   let month = 30; //days
  4.   let copyArray = array.slice();
  5.   let quantityFood = copyArray.shift() * gram;
  6.   let hay = Number(copyArray.shift()) * gram; // сено
  7.   let cover = Number(copyArray.shift()) * gram;
  8.   let weight = Number(copyArray.shift()) * gram;
  9.   let isEnough = true;
  10.  
  11.   for (let day = 1; day <= month; day++) {
  12.     quantityFood -= 300;
  13.  
  14.     if (quantityFood <= 0 || hay <= 0 || cover <= 0) {
  15.       isEnough = false;
  16.       break;
  17.     }
  18.  
  19.     if (day % 2 === 0) {
  20.       hay -= quantityFood * 0.05;
  21.     }
  22.  
  23.     if (day % 3 === 0) {
  24.       cover -= weight / 3;
  25.     }
  26.   }
  27.   if (!isEnough) {
  28.     console.log(`Merry must go to the pet store!`);
  29.   } else {
  30.     console.log(
  31.       `Everything is fine! Puppy is happy! Food: ${(
  32.         quantityFood / gram
  33.       ).toFixed(2)}, Hay: ${(hay / gram).toFixed(2)}, Cover: ${(
  34.         cover / gram
  35.       ).toFixed(2)}.`
  36.     );
  37.   }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement