Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function foodForPets(input) {
- let index = 0;
- let days = Number(input[index]);
- index++;
- let foodQuantity = Number(input[index]);
- index++;
- let dogQuantity = Number(input[index]);
- index++;
- let catQuantity = Number(input[index]);
- index++;
- let currentDay = 1;
- let dogFood = 0;
- let catFood = 0;
- let biscuits = 0;
- while(currentDay <= days) {
- if(currentDay % 3 == 0) {
- biscuits += (dogQuantity + catQuantity) * 0.1;
- }
- dogFood += dogQuantity;
- catFood += catQuantity;
- dogQuantity = input[index];
- index++;
- catQuantity = input[index];
- index++;
- currentDay++;
- }
- let totalFood = dogFood + catFood;
- let dogPercent = ((dogFood / totalFood) * 100).toFixed(2);
- let catPercent = ((catFood / totalFood) * 100).toFixed(2);
- let totalPercent = ((totalFood / foodQuantity) * 100).toFixed(2);
- console.log(`Total eaten biscuits: ${(Math.round)(biscuits)}gr.`);
- console.log(`${totalPercent}% of the food has been eaten.`);
- console.log(`${dogPercent}% eaten from the dog.`);
- console.log(`${catPercent}% eaten from the cat.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement