-Enigmos-

pastryShop.js

Oct 31st, 2021 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pastryShop(input) {
  2.     let pastryType = input[0];
  3.     let quantity = Number(input[1]);
  4.     let day = Number(input[2]);
  5.     let pricePerPastry = 0;
  6.    
  7.     switch(pastryType) {
  8.         case "Cake":
  9.             if (day <= 15) {
  10.                 pricePerPastry = 24;
  11.             } else {
  12.                 pricePerPastry = 28.70;
  13.             }
  14.             break;
  15.         case "Souffle":
  16.             if (day <= 15) {
  17.                 pricePerPastry = 6.66;
  18.             } else {
  19.                 pricePerPastry = 9.80;
  20.             }
  21.             break;
  22.         case "Baklava":
  23.             if (day <= 15) {
  24.                 pricePerPastry = 12.60;
  25.             } else {
  26.                 pricePerPastry = 16.98;
  27.             }
  28.             break;
  29.     }
  30.  
  31.     let price = quantity * pricePerPastry;
  32.  
  33.     if (day <= 22) {
  34.         if (price >= 100 && price <= 200) {
  35.             price = price - (price * 0.15);
  36.         } else if (price > 200) {
  37.             price = price - (price * 0.25);
  38.         }
  39.     }
  40.    
  41.     if (day <= 15) {
  42.         price = price - (price * 0.1);
  43.     }
  44.  
  45.     console.log(price.toFixed(2));
  46. }
Add Comment
Please, Sign In to add comment