Advertisement
vladovip

Guinea Pig _ MidExamPrepar_ JS Fund.

Feb 21st, 2022
970
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // TO BE REFINED
  2.  
  3. function guineaPig(inputArr) {
  4.   let foodQuantity = Number(inputArr.shift()); // quantity food in kilograms
  5.   // console.log(foodQuantity);
  6.   let hayQuantity = Number(inputArr.shift()); // quantity hay in kilograms
  7.   let coverQuantity = Number(inputArr.shift()); // quantity cover in kilograms
  8.   let guineaWeight = Number(inputArr.shift()); // guinea's weight in kilograms
  9.   day = 1;
  10.  
  11.  
  12.     while (day <= 30 ){
  13.        
  14.         if (day % 2 !== 0 && day % 3 !== 0 ){
  15.             foodQuantity -= 0.300;
  16.         }
  17.         if ( day % 2 === 0 ){
  18.         foodQuantity -= 0.300;
  19.         hayQuantity-= 0.05 * foodQuantity;
  20.         }
  21.          if (day % 3 === 0 ){
  22.             coverQuantity-= (1/3 * guineaWeight);
  23.         }  
  24.         day++;
  25.     }
  26.  
  27.  
  28.   if (foodQuantity > 0 && hayQuantity > 0 && coverQuantity > 0) {
  29.     console.log(
  30.       `Everything is fine! Puppy is happy! Food: ${foodQuantity.toFixed(2)}, Hay: ${hayQuantity.toFixed(2)}, Cover: ${coverQuantity.toFixed(2)}.`
  31.     );
  32.   } else {
  33.     console.log(`Merry must go to the pet store!`);
  34.   }
  35.  
  36. }
  37.  
  38. guineaPig(["10", "5", "5.2", "1"]);
  39.  
  40. // Expected Result:  Everything is fine! Puppy is happy! Food: 1.00, Hay: 1.10, Cover: 1.87
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement