Advertisement
Liliana797979

viarno reshenie food for pets

Feb 14th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(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.  
  21.         dogFood += dogQuantity;
  22.         catFood += catQuantity;
  23.         dogQuantity = Number(input[index]);
  24.         index++;
  25.         catQuantity = Number(input[index]);
  26.         index++;
  27.         currentDay++;
  28.     }
  29.  
  30.     let total = dogFood + catFood;
  31.     let dogP = ((dogFood / total) * 100).toFixed(2);
  32.     let catP = ((catFood / total) * 100).toFixed(2);
  33.     let totalP = ((total / foodQuantity) * 100).toFixed(2);
  34.     console.log(`Total eaten biscuits: ${Math.round(biscuits)}gr.`);
  35.     console.log(`${totalP}% of the food has been eaten.`);
  36.     console.log(`${dogP}% eaten from the dog.`);
  37.     console.log(`${catP}% eaten from the cat.`);
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement