Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let days = Number(input.shift());
- let quantity = Number(input.shift());
- let dogFood = 0;
- let catFood = 0;
- let totalEat = 0;
- let daysCounter = 0;
- let bisquit = 0;
- for (let i = 0; i < days; i++) {
- dogEat = Number(input.shift());
- dogFood += dogEat;
- catEat = Number(input.shift());
- catFood += catEat;
- lastMeal = dogEat + catEat;
- totalEat += dogEat + catEat;
- daysCounter++;
- if (daysCounter == 3) {
- bisquit = lastMeal * 0.10;
- }
- }
- let avarage = totalEat / quantity * 100;
- let dogAvarage = dogFood / totalEat * 100;
- let CatAvarage = catFood / totalEat * 100;
- console.log(`Total eaten biscuits: ${Math.round(bisquit)}gr.`)
- console.log(`${avarage.toFixed(2)}% of the food has been eaten.`)
- console.log(`${dogAvarage.toFixed(2)}% eaten from the dog.`)
- console.log(`${CatAvarage.toFixed(2)}% eaten from the cat.`)
- }
- solve([3,
- 500,
- 100,
- 30,
- 110,
- 25,
- 120,
- 35
- ]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement