Advertisement
Liliana797979

coffee machine

Dec 22nd, 2020
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function coffeeMachine(arg1, arg2, arg3) {
  2.     let drink = arg1;
  3.     let sugar = arg2;
  4.     let drinksCount = Number(arg3);
  5.  
  6.     switch (drink) {
  7.         case "Espresso":
  8.             switch (sugar) {
  9.                 case "Without":
  10.                    totalPrice = drinksCount * 0.9;
  11.                     break;
  12.                 case "Normal":
  13.                     totalPrice = drinksCount * 1.0;
  14.                     break;
  15.                 case "Extra":
  16.                     totalPrice = drinksCount * 1.2;
  17.                     break;
  18.             }
  19.         case "Cappuccino":
  20.             switch (sugar) {
  21.                 case "Without":
  22.                     totalPrice = drinksCount * 1.0;
  23.                     break;
  24.                 case "Normal":
  25.                     totalPrice = drinksCount * 1.2;
  26.                     break;
  27.                 case "Extra":
  28.                     totalPrice = drinksCount * 1.6;
  29.                     break;
  30.             }
  31.         case "Tea":
  32.             switch (sugar) {
  33.                 case "Without":
  34.                     totalPrice = drinksCount * 0.5;
  35.                     break;
  36.                 case "Normal":
  37.                     totalPrice = drinksCount * 0.6;
  38.                     break;
  39.                 case "Extra":
  40.                     totalPrice = drinksCount * 0.7;
  41.                     break;
  42.             }  
  43.             break;
  44.     }
  45.  
  46.     if (drink === "Without") {
  47.         let totalPrice = totalPrice - (totalPrice * 0.65);
  48.  
  49.     } else if (drink === "Espresso" && drinksCount >= 5) {
  50.         totalPrice = totalPrice - (totalPrice * 0.75);
  51.  
  52.     } else if (totalPrice >= 15) {
  53.         totalPrice = totalPrice - (totalPrice * 0.8);
  54.     }
  55.  
  56.     console.log(`You bought ${drinksCount} cups of ${drink} for ${(totalPrice).toFixed(2)} lv.`);
  57. }
  58.  
  59. coffeeMachine("Cappuccino", "Normal", "13");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement