Advertisement
Liliana797979

coffee

Dec 23rd, 2020
91
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.             if (sugar === "Without") {
  9.                    totalPrice += drinksCount * 0.9;
  10.                    totalPrice -= drinksCount * 0.35;
  11.                     break;
  12.              } else if (sugar === "Normal") {
  13.                 totalPrice += drinksCount * 1;
  14.              } else if (sugar === "Extra") {
  15.                 totalPrice += drinksCount * 1.2;
  16.              }
  17.                     break;
  18.  
  19.  
  20.             }
  21.             if (drink === "Espresso" && drinksCount >= 5) {
  22.                 totalPrice -= totalPrice * 0.25;
  23.             }
  24.             if (totalPrice > 15) {
  25.                 totalPrice -= totalPrice * 0.2;
  26.             }
  27.         case "Cappuccino":
  28.             switch (sugar) {
  29.                 case "Without":
  30.                     totalPrice = drinksCount * 1.0;
  31.                     break;
  32.                 case "Normal":
  33.                     totalPrice = drinksCount * 1.2;
  34.                     break;
  35.                 case "Extra":
  36.                     totalPrice = drinksCount * 1.6;
  37.                     break;
  38.             }
  39.         case "Tea":
  40.             switch (sugar) {
  41.                 case "Without":
  42.                     totalPrice = drinksCount * 0.5;
  43.                     break;
  44.                 case "Normal":
  45.                     totalPrice = drinksCount * 0.6;
  46.                     break;
  47.                 case "Extra":
  48.                     totalPrice = drinksCount * 0.7;
  49.                     break;
  50.             }  
  51.             break;
  52.     }
  53.  
  54.  
  55.     console.log(`You bought ${drinksCount} cups of ${drink} for ${(totalPrice).toFixed(2)} lv.`);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement