Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function catFood(input) {
- let index = 0;
- let catNumber = Number(input[index]);
- index++;
- let group1 = 0;
- let group2 = 0;
- let group3 = 0;
- let catFoodTotal = 0;
- let pricePerKg = 12.45;
- for (i = 0; i < catNumber; i++) {
- let catFood = Number(input[index]);
- index++;
- catFoodTotal += catFood / 1000;
- if (catFood >= 100 && catFood < 200) {
- group1++;
- } else if (catFood >= 200 && catFood < 300) {
- group2++;
- } else if (catFood >= 300 && catFood < 400) {
- group3++;
- }
- }
- let priceTotal = catFoodTotal * pricePerKg;
- console.log(`Group 1: ${group1} cats.`);
- console.log(`Group 2: ${group2} cats.`);
- console.log(`Group 3: ${group3} cats.`);
- console.log(`Price for food per day: ${priceTotal.toFixed(2)} lv.`);
- }
- catFood(["6", "102", "236", "123", "399", "342", "222"]);
- catFood(["10", "256", "348", "198", "322", "186", "294", "321", "100", "200", "300"]);
- catFood(["7", "100", "200", "342", "300", "234", "123", "212"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement