Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function coffeeMachine(input) {
  2.  
  3.     let drink = String(input.shift());
  4.     let sugar = String(input.shift());
  5.     let count = Number(input.shift());
  6.  
  7.     switch (drink) {
  8.  
  9.         case 'Espresso':
  10.  
  11.             switch (sugar) {
  12.  
  13.                 case 'Without':
  14.                     if (count >= 5) {
  15.                         price = 0.90;
  16.                         discount1 = price - price * 0.35;
  17.                         discount2 = discount1 - discount1 * 0.25;
  18.                         totalSum = count * discount2;
  19.                     } else if (count < 5) {
  20.                         price = 0.90;
  21.                         discount = price - price * 0.35;
  22.                         totalSum = count * discount;
  23.                     }
  24.                     break;
  25.  
  26.                 case 'Normal':
  27.                     if (count >= 5) {
  28.                         price = 1;
  29.                         discount = price - price * 0.25;
  30.                         totalSum = count * discount;
  31.                     } else if (count < 5) {
  32.                         price = 1;
  33.                         totalSum = count * price;
  34.                     }
  35.                     break;
  36.  
  37.                 case 'Extra':
  38.                     if (count >= 5) {
  39.                         price = 1.2;
  40.                         discount = price - price * 0.25;
  41.                         totalSum = count * discount;
  42.                     } else if (count < 5) {
  43.                         price = 1.2;
  44.                         totalSum = count * price;
  45.                     }
  46.                     break;
  47.             }
  48.             break;
  49.  
  50.         case 'Cappuccino':
  51.  
  52.             switch (sugar) {
  53.  
  54.                 case 'Without':
  55.                     price = 1.00;
  56.                     discount = price - price * 0.35;
  57.                     totalSum = count * discount;
  58.  
  59.                     break;
  60.  
  61.                 case 'Normal':
  62.  
  63.                     price = 1.20;
  64.                     totalSum = count * price;
  65.                     break;
  66.  
  67.                 case 'Extra':
  68.                     price = 1.60;
  69.                     totalSum = count * price;
  70.                     break;
  71.             }
  72.         case 'Tea':
  73.  
  74.             switch (sugar) {
  75.  
  76.                 case 'Without':
  77.                     price = 0.50;
  78.                     discount = price - price * 0.35;
  79.                     totalSum = count * discount;
  80.  
  81.                     break;
  82.  
  83.                 case 'Normal':
  84.  
  85.                     price = 0.60;
  86.                     totalSum = count * price;
  87.                     break;
  88.  
  89.                 case 'Extra':
  90.                     price = 0.70;
  91.                     totalSum = count * price;
  92.                     break;
  93.             }
  94.  
  95.  
  96.             break;
  97.     }
  98.     break;
  99.  
  100.  
  101.  
  102.     if (totalSum <= 15) {
  103.         console.log(console.log(`You bought ${count} cups of ${drink} for ${(totalSum).toFixed(2)} lv.`));
  104.     } else {
  105.         console.log(console.log(`You bought ${count} cups of ${drink} for ${(totalSum - totalSum * 0.20).toFixed(2)} lv.`));
  106.     }
  107.  
  108. }
  109. coffeeMachine(['Cappuccino', 'Normal', 13]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement