ExGiX

Untitled

Apr 2nd, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function foodForPets (input) {
  2.  
  3. let days = Number(input.shift());
  4. let food = Number(input.shift());
  5. let countDays = 0;
  6.  
  7. let FoodEaten = 0; //
  8.  
  9.  
  10. let allFood = 0;
  11. let dogFood = 0;
  12. let catFood = 0;
  13.  
  14.  
  15.  
  16. let biscuits = 0;
  17.  
  18. let cats = 0;
  19. let dogs = 0;
  20.  
  21. for(let i = 0; i < days; i++ ) {
  22. countDays++;
  23. let dogQuantity = Number(input.shift());
  24. let catQuantity = Number(input.shift());
  25. let eatenFromDog = 0;
  26. let eatenFromCat = 0;
  27.  
  28. FoodEaten += dogQuantity + catQuantity;
  29. dogs += dogQuantity;
  30. cats += catQuantity;
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. if(countDays % 3 == 0) {
  38.  
  39.  
  40. biscuits = (dogQuantity + catQuantity) * 0.10;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
  50. allFood = ((FoodEaten / food) * 100);
  51. dogFood = ((dogs / FoodEaten) * 100)
  52. catFood = ((cats / FoodEaten) * 100)
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. console.log(`Total eaten biscuits: ${Math.ceil(biscuits)}gr.`)
  61. console.log(`${allFood.toFixed(2)}% of the food has been eaten.`)
  62. console.log(`${dogFood.toFixed(2)}% eaten from the dog.`)
  63. console.log(`${catFood.toFixed(2)}% eaten from the cat.`)
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment