Advertisement
Spocoman

Cat Food

Jan 8th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function catFood(input) {
  2.  
  3.     let num = Number(input.shift());
  4.  
  5.     let firstGroup = 0;
  6.     let secondGroup = 0;
  7.     let thirdGroup = 0;
  8.     let totalFood = 0;
  9.  
  10.     for (let i = 0; i < num; i++) {
  11.         let food = Number(input.shift());
  12.         totalFood += food;
  13.         if (food >= 100 && food < 200) {
  14.             firstGroup++;
  15.         } else if (food >= 200 && food < 300) {
  16.             secondGroup++;
  17.         } else if (food >= 300 && food < 400) {
  18.             thirdGroup++;
  19.         }
  20.     }
  21.     let price = totalFood * 0.01245;
  22.  
  23.     console.log(`Group 1: ${firstGroup} cats.`);
  24.     console.log(`Group 2: ${secondGroup} cats.`);
  25.     console.log(`Group 3: ${thirdGroup} cats.`);
  26.     console.log(`Price for food per day: ${price.toFixed(2)} lv.`);
  27.  
  28. }
  29.  
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement