Advertisement
ErolKZ

Untitled

Jun 15th, 2021
56
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 + 2 + countDays; 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. percentWholeFood = (foodPerDay / wholeFood) * 100;
  56. dogPercent = (dogEat / foodPerDay) * 100;
  57. catPercent = (catEat / foodPerDay) * 100;
  58. coockies = Math.round(coockies);
  59.  
  60.  
  61. console.log(`Total eaten biscuits: ${coockies}gr.`);
  62. console.log(`${percentWholeFood.toFixed(2)}% of the food has been eaten.`);
  63. console.log(`${dogPercent.toFixed(2)}% eaten from the dog.`);
  64. console.log(`${catPercent.toFixed(2)}% eaten from the cat.`);
  65.  
  66.  
  67. }
  68.  
  69.  
  70. solve([
  71.  
  72. '3',
  73. '500',
  74. '100',
  75. '30',
  76. '110',
  77. '25',
  78. '120',
  79. '35',
  80.  
  81. ]);
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement