Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
78
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.                     }break;
  24.  
  25.                 case 'Normal':
  26.                     if (count >= 5) {
  27.                         price = 1;
  28.                         discount = price - price * 0.25;
  29.                         totalSum = count * discount;
  30.                     } else if (count < 5) {
  31.                         price = 1;
  32.                         totalSum = count * price;
  33.                     }break;
  34.  
  35.                 case 'Extra':
  36.                     if (count >= 5) {
  37.                         price = 1.2;
  38.                         discount = price - price * 0.25;
  39.                         totalSum = count * discount;
  40.                     } else if (count < 5) {
  41.                         price = 1.2;
  42.                         totalSum = count * price;
  43.                     } break;
  44.             }
  45.             break;
  46.  
  47.         case 'Cappuccino':
  48.  
  49.             switch (sugar) {
  50.  
  51.                 case 'Without':
  52.                     price = 1.00;
  53.                     discount = price - price * 0.35;
  54.                     totalSum = count * discount;
  55.  
  56.                 break;
  57.  
  58.                 case 'Normal':
  59.  
  60.                     price = 1.20;
  61.                     totalSum = count * price;
  62.                 break;
  63.  
  64.                 case 'Extra':
  65.                     price = 1.60;
  66.                     totalSum = count * price;
  67.                 break;
  68.             }
  69.         break;
  70.  
  71.         case 'Tea':
  72.  
  73.             switch (sugar) {
  74.  
  75.                 case 'Without':
  76.                     price = 0.50;
  77.                     discount = price - price * 0.35;
  78.                     totalSum = count * discount;
  79.  
  80.                  break;
  81.  
  82.                 case 'Normal':
  83.  
  84.                     price = 0.60;
  85.                     totalSum = count * price;
  86.                 break;
  87.  
  88.                 case 'Extra':
  89.                     price = 0.70;
  90.                     totalSum = count * price;
  91.                  break;
  92.             }
  93.     break;
  94.  
  95.     }
  96.  
  97.  
  98.  
  99.     if (totalSum <= 15) {
  100.         console.log(console.log(`You bought ${count} cups of ${drink} for ${(totalSum).toFixed(2)} lv.`));
  101.     } else {
  102.         console.log(console.log(`You bought ${count} cups of ${drink} for ${(totalSum - totalSum * 0.20).toFixed(2)} lv.`));
  103.     }
  104.  
  105. }
  106. coffeeMachine(['Cappuccino','Normal',13]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement