Advertisement
didkoslawow

Untitled

Feb 19th, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cookingClass(input) {
  2.     let [budget, studentsCount, flourPrice, eggPrice, apronPrice] = input;
  3.     let totalFlour = 0;
  4.     let totalEggs = 0;
  5.     let totalApron = 0;
  6.  
  7.     for (let i = 1; i <= studentsCount; i++) {
  8.         totalEggs += 10;
  9.         totalFlour++;
  10.         totalApron++;
  11.         if (i % 5 === 0) {
  12.             totalFlour--;
  13.         }
  14.     }
  15.     totalApron *= 1.2;
  16.  
  17.     let totalPrice = totalFlour * flourPrice + totalEggs * eggPrice + Math.ceil(totalApron) * apronPrice;
  18.    
  19.     if (totalPrice <= budget) {
  20.         console.log(`Items purchased for ${totalPrice.toFixed(2)}$.`);
  21.     } else {
  22.         console.log(`${(totalPrice - budget).toFixed(2)}$ more needed.`);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement