StefanShivarov

04. Cat Food

Jul 25th, 2021 (edited)
802
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function zad1(foodAmounts){
  2.  
  3.     let smallCats = [];
  4.     let bigCats = [];
  5.     let hugeCats = [];
  6.     let totalGrams = 0;
  7.     let quantity = Number(foodAmounts[0]);
  8.  
  9.     for(let i = 1; i <= quantity; i++){
  10.  
  11.         if(Number(foodAmounts[i]) >= 100 && Number(foodAmounts[i]) < 200)){
  12.  
  13.             smallCats.push(Number(foodAmounts[i]));
  14.         }else if(Number(foodAmounts[i]) >= 200 && Number(foodAmounts[i]) < 300){
  15.  
  16.             bigCats.push(Number(foodAmounts[i]));
  17.         }else if(Number(foodAmounts[i]) >= 300 && Number(foodAmounts[i]) < 400){
  18.            
  19.             hugeCats.push(Number(foodAmounts[i]));
  20.         }
  21.  
  22.         totalGrams += Number(foodAmounts[i]);
  23.     }
  24.  
  25.     console.log(`Group 1: ${smallCats.length} cats.`);
  26.     console.log(`Group 2: ${bigCats.length} cats.`);
  27.     console.log(`Group 3: ${hugeCats.length} cats.`);
  28.  
  29.     let pricePerDay = (totalGrams/1000) * 12.45;
  30.  
  31.     console.log(`Price for food per day: ${pricePerDay.toFixed(2)} lv.`);
  32. }
  33.  
RAW Paste Data