Didart

Small Shop

Mar 16th, 2022 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function smallShop(input){
  2.     let product = input.shift();
  3.     let city = input.shift();
  4.     let quantity = Number(input.shift());
  5.  
  6.     let totalPrice = 0;
  7.     if (city === "Sofia"){
  8.         switch (product) {
  9.             case 'coffee' :
  10.                 totalPrice = 0.50 * quantity;
  11.             break;
  12.             case 'water' :
  13.                 totalPrice = 0.80 * quantity;
  14.             break;
  15.             case 'beer' :
  16.                 totalPrice = 1.20 * quantity;
  17.             break;
  18.             case 'sweets' :
  19.                 totalPrice = 1.45 * quantity;
  20.             break;
  21.             case 'peanuts' :
  22.                 totalPrice = 1.60 * quantity;
  23.             break;
  24.         }
  25.     } else if (city === "Plovdiv"){
  26.         switch (product) {
  27.             case 'coffee' :
  28.                 totalPrice = 0.40 * quantity;
  29.             break;
  30.             case 'water' :
  31.                 totalPrice = 0.70 * quantity;
  32.             break;
  33.             case 'beer' :
  34.                 totalPrice = 1.15 * quantity;
  35.             break;
  36.             case 'sweets' :
  37.                 totalPrice = 1.30 * quantity;
  38.             break;
  39.             case 'peanuts' :
  40.                 totalPrice = 1.50 * quantity;
  41.             break;
  42.         }
  43.     } else {
  44.         switch (product) {
  45.             case 'coffee' :
  46.                 totalPrice = 0.45 * quantity;
  47.             break;
  48.             case 'water' :
  49.                 totalPrice = 0.70 * quantity;
  50.             break;
  51.             case 'beer' :
  52.                 totalPrice = 1.10 * quantity;
  53.             break;
  54.             case 'sweets' :
  55.                 totalPrice = 1.35 * quantity;
  56.             break;
  57.             case 'peanuts' :
  58.                 totalPrice = 1.55 * quantity;
  59.             break;
  60.         }
  61.     }
  62.     console.log(totalPrice);
  63. }
  64.  
  65. smallShop(["coffee", "Varna", "2"])
  66.  
  67.  
  68.  
Add Comment
Please, Sign In to add comment