Advertisement
ErolKZ

Untitled

Jun 15th, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1.  
  2. function solve(input) {
  3.  
  4. let countDays = Number(input[0]);
  5.  
  6. let wholeFood = Number(input[1]);
  7.  
  8. let foodPerDay = 0;
  9. let percentWholeFood = 0;
  10. let foodDogDay = 0;
  11. let foodCatDay = 0;
  12. let counter = 0;
  13. let coockies = 0;
  14. let foodOnlyTheDay = 0;
  15. let dogEat = 0;
  16. let catEat = 0;
  17. let dogPercent = 0;
  18. let catPercent = 0;
  19. let result = 0;
  20.  
  21.  
  22. for (let i = 2; i < countDays + 5; i++) {
  23.  
  24. foodDogDay = +input[i];
  25.  
  26. foodCatDay = +input[i + 1];
  27.  
  28. i = i + 1;
  29.  
  30. foodPerDay = foodPerDay + (foodDogDay + foodCatDay);
  31.  
  32. foodOnlyTheDay = foodDogDay + foodCatDay;
  33.  
  34. dogEat += foodDogDay;
  35. catEat += foodCatDay;
  36.  
  37.  
  38.  
  39. counter += 1;
  40.  
  41.  
  42. result = counter / 3;
  43.  
  44. if (Number.isInteger(result)) {
  45.  
  46. coockies = coockies + foodOnlyTheDay * (10 / 100);
  47.  
  48.  
  49. }
  50.  
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57. percentWholeFood = (foodPerDay / wholeFood) * 100;
  58. dogPercent = (dogEat / foodPerDay) * 100;
  59. catPercent = (catEat / foodPerDay) * 100;
  60. coockies = Math.round(coockies);
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. console.log(`Total eaten biscuits: ${coockies}gr.`);
  70. console.log(`${percentWholeFood.toFixed(2)}% of the food has been eaten.`);
  71. console.log(`${dogPercent.toFixed(2)}% eaten from the dog.`);
  72. console.log(`${catPercent.toFixed(2)}% eaten from the cat.`);
  73.  
  74.  
  75. }
  76.  
  77.  
  78. solve([
  79. '3',
  80. '500',
  81. '100',
  82. '30',
  83. '110',
  84. '25',
  85. '120',
  86. '35',
  87.  
  88. ]);
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement