gskorchev

small shop

Jan 28th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shop(input) {
  2.     let productName = input.shift();
  3.     let city = input.shift();
  4.     let quantity = Number(input.shift());
  5.     let price = 0;
  6.     if (city == "Sofia") {
  7.         if (productName == "coffee") {
  8.             price = quantity * 0.50;
  9.         } else if (productName == "water") {
  10.             price = quantity * 0.80;
  11.         } else if (productName == "beer") {
  12.             price = quantity * 1.20;
  13.         } else if (productName == "sweets") {
  14.             price = quantity * 1.45;
  15.         } else if (productName == "peanuts") {
  16.             price = quantity * 1.60;
  17.         }
  18.     }
  19.  
  20.     if (city == "Plovdiv") {
  21.         if (productName == "coffee") {          
  22.             price = quantity * 0.40;
  23.         } else if (productName == "water") {
  24.             price = quantity * 0.70;
  25.         } else if (productName == "beer") {
  26.             price = quantity * 1.15;
  27.         } else if (productName == "sweets") {
  28.             price = quantity * 1.30;
  29.         } else if (productName == "peanuts") {
  30.             price = quantity * 1.50;
  31.         }
  32.     }
  33.     if (city == "Varna") {
  34.         if (productName == "coffee") {
  35.             price = quantity * 0.45;
  36.         } else if (productName == "water") {
  37.             price = quantity * 0.70;
  38.         } else if (productName == "beer") {
  39.             price = quantity * 1.10;
  40.         } else if (productName == "sweets") {
  41.             price = quantity * 1.35;
  42.         } else if (productName == "peanuts") {
  43.             price = quantity * 1.55;
  44.         }
  45.     }
  46.     console.log(price.toFixed(2));
  47. }
  48.  
  49. shop(["water", "Plovdiv", 3]);
Advertisement
Add Comment
Please, Sign In to add comment