Advertisement
Guest User

Solution

a guest
Mar 29th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let drinkName = String(input.shift());
  3.     let sugarQntt = String(input.shift());
  4.     let drinkNum = Number(input.shift());
  5.     let totalPrice = 0;
  6.  
  7.     switch (drinkName) {
  8.         case 'Espresso':
  9.             switch (sugarQntt) {
  10.                 case 'Without':
  11.                     totalPrice = drinkNum * 0.90;
  12.                     break;
  13.  
  14.                     case 'Normal':
  15.                         totalPrice = drinkNum * 1;
  16.                         break;
  17.  
  18.                         case 'Extra':
  19.                             totalPrice = drinkNum * 1.20;
  20.                             break;
  21.                            
  22.             }
  23.  
  24.             if (drinkNum > 5) {
  25.                 totalPrice *= 0.75;
  26.             }
  27.  
  28.             break;
  29.  
  30.             case 'Cappuccino':
  31.                 switch (sugarQntt) {
  32.                     case 'Without':
  33.                         totalPrice = drinkNum * 1;
  34.                         break;
  35.  
  36.                         case 'Normal':
  37.                             totalPrice = drinkNum * 1.20;
  38.                             break;
  39.  
  40.                             case 'Extra':
  41.                                 totalPrice = drinkNum * 1.60;
  42.                                 break;
  43.                 }
  44.  
  45.                 break;
  46.  
  47.                 case 'Tea':
  48.                     switch (sugarQntt) {
  49.                         case 'Without':
  50.                             totalPrice = drinkNum * 0.50;
  51.                             break;
  52.  
  53.                             case 'Normal':
  54.                                 totalPrice = drinkNum * 0.60;
  55.                                 break;
  56.  
  57.                                 case 'Extra':
  58.                                     totalPrice = drinkNum * 0.70;
  59.                                     break;
  60.                     }
  61.  
  62.                     break;
  63.            
  64.     }
  65.  
  66.     if (sugarQntt === 'Without') {
  67.         totalPrice *= 0.65;
  68.     }
  69.  
  70.     if (totalPrice > 15) {
  71.         totalPrice *= 0.80;
  72.     }
  73.  
  74.     console.log(`You bought ${drinkNum} cups of ${drinkName} for ${totalPrice.toFixed(2)} lv.`);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement