Liliana797979

merry and puppy - problem1 - mid exam

Jul 18th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve1(input) {
  2.     let foodInKilograms = Number(input[0]);
  3.     //console.log(foodInKilograms);
  4.     let hayInKilograms = Number(input[1]);
  5.     //console.log(hayInKilograms);
  6.     let coverInKilograms = Number(input[2]);
  7.     //console.log(coverInKilograms);
  8.     let guineaWeightInKilograms = Number(input[3]);
  9.    // console.log(guineaWeightInKilograms);
  10.  
  11. let day = 0;
  12. let foodInGrames = foodInKilograms * 1000;
  13. let foodInGramesInDay = foodInGrames - 300;
  14. let food = foodInGrames - 9000;
  15. let hayInGrames = hayInKilograms * 1000;
  16. let coverInGrames = coverInKilograms * 1000;
  17. let weigthInGrames = guineaWeightInKilograms * 1000;
  18. let foodInDay = (foodInGrames / 30).toFixed(2);
  19. let foodInTwoDay = foodInGrames - 600;
  20. console.log(foodInTwoDay);
  21. let hay = 0;
  22. let cover = 0;
  23. let hayInDay = hayInGrames - hay;
  24. if (day % 2 === 0) {
  25.    hayIn = foodInTwoDay * 0.05;
  26.    
  27. }
  28. let hayU = hayInGrames - hayIn;
  29.  
  30.     if (day % 3 === 0) {
  31.         cover = coverInGrames - weigthInGrames / 3;
  32.     }
  33.  
  34. while (foodInGrames >= 0) {
  35.     day++;
  36.  
  37.  
  38.  
  39. if(foodInGrames > 0 && hayInGrames > 0 && weigthInGrames > 0)  {
  40.     console.log(`Everything is fine! Puppy is happy! Food: ${(food / 1000).toFixed(2)}, Hay: ${(hayInGrames/15).toFixed(2)}, Cover: ${cover.toFixed(2)}`);
  41. } else if (foodInGrames == 0 || hayInGrames == 0 || coverInGrames == 0) {
  42.     console.log(`Marry must go to pet store!`);
  43. }
  44. break;
  45. }
  46. }
  47.  
  48. solve1(["10",
  49. "5",
  50. "5.2",
  51. "1"]);
Advertisement
Add Comment
Please, Sign In to add comment