Pijomir

Guinea Pig

Oct 13th, 2023
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkIfGarmentsWillBeEnough(input) {
  2.     let foodInGrams = Number(input.shift()) * 1000;
  3.     let hayInGrams = Number(input.shift()) * 1000;
  4.     let coverInGrams = Number(input.shift()) * 1000;
  5.     let pigWeight = Number(input.shift()) * 1000;
  6.     for (let i = 1; i <= 30; i++) {
  7.         foodInGrams -= 300;
  8.         if (i % 2 === 0) {
  9.             hayInGrams -= foodInGrams * 0.05;
  10.         }
  11.  
  12.         if (i % 3 === 0) {
  13.             coverInGrams -= pigWeight / 3;
  14.         }
  15.  
  16.         if (foodInGrams < 0 || hayInGrams < 0 || coverInGrams < 0) {
  17.             return 'Merry must go to the pet store!';
  18.         }
  19.     }
  20.  
  21.     return `Everything is fine! Puppy is happy! Food: ${(foodInGrams / 1000).toFixed(2)}, Hay: ${(hayInGrams / 1000).toFixed(2)}, Cover: ${(coverInGrams / 1000).toFixed(2)}.`
  22. }
Advertisement
Add Comment
Please, Sign In to add comment