Advertisement
Liliana797979

food for pets

Jan 2nd, 2021
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function foodForPets(input) {
  2.     let index = 0;
  3.     let days = Number(input[index]);
  4.     index++;
  5.     let foodQuantity = Number(input[index]);
  6.     index++;
  7.     let dogQuantity = Number(input[index]);
  8.     index++;
  9.     let catQuantity = Number(input[index]);
  10.     index++;
  11.     let currentDay = 1;
  12.     let dogFood = 0;
  13.     let catFood = 0;
  14.     let biscuits = 0;
  15.  
  16.     while(currentDay <= days) {
  17.         if(currentDay % 3 == 0) {
  18.             biscuits += (dogQuantity + catQuantity) * 0.1;
  19.         }
  20.         dogFood += dogQuantity;
  21.         catFood += catQuantity;
  22.         dogQuantity = input[index];
  23.         index++;
  24.         catQuantity = input[index];
  25.         index++;
  26.         currentDay++;
  27.     }
  28.  
  29.     let totalFood = dogFood + catFood;
  30.     let dogPercent = ((dogFood / totalFood) * 100).toFixed(2);
  31.     let catPercent = ((catFood / totalFood) * 100).toFixed(2);
  32.     let totalPercent = ((totalFood / foodQuantity) * 100).toFixed(2);
  33.     console.log(`Total eaten biscuits: ${(Math.round)(biscuits)}gr.`);
  34.     console.log(`${totalPercent}% of the food has been eaten.`);
  35.     console.log(`${dogPercent}% eaten from the dog.`);
  36.     console.log(`${catPercent}% eaten from the cat.`);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement