Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function foodForPets (input) {
- let days = Number(input.shift());
- let food = Number(input.shift());
- let countDays = 0;
- let FoodEaten = 0; //
- let allFood = 0;
- let dogFood = 0;
- let catFood = 0;
- let biscuits = 0;
- let cats = 0;
- let dogs = 0;
- for(let i = 0; i < days; i++ ) {
- countDays++;
- let dogQuantity = Number(input.shift());
- let catQuantity = Number(input.shift());
- let eatenFromDog = 0;
- let eatenFromCat = 0;
- FoodEaten += dogQuantity + catQuantity;
- dogs += dogQuantity;
- cats += catQuantity;
- if(countDays % 3 == 0) {
- biscuits = (dogQuantity + catQuantity) * 0.10;
- }
- }
- allFood = ((FoodEaten / food) * 100);
- dogFood = ((dogs / FoodEaten) * 100)
- catFood = ((cats / FoodEaten) * 100)
- console.log(`Total eaten biscuits: ${Math.ceil(biscuits)}gr.`)
- console.log(`${allFood.toFixed(2)}% of the food has been eaten.`)
- console.log(`${dogFood.toFixed(2)}% eaten from the dog.`)
- console.log(`${catFood.toFixed(2)}% eaten from the cat.`)
- }
Advertisement
Add Comment
Please, Sign In to add comment