Advertisement
PowerCell46

shop task JS

Sep 21st, 2022 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function shopTask(input) {
  2. let product = input[0];
  3. let city = input[1];
  4. let quantity = Number(input[2]);
  5. let price = 0;
  6.  
  7. if(city === "Sofia") {
  8.  if(product === "water") {
  9.     price = Number(0.80);
  10.  } else if(product === "coffee") {
  11.      price = Number(0.50);
  12.  } else if(product === "beer") {
  13.      price = Number(1.20);
  14.  } else if(product === "sweets") {
  15.      price = Number(1.45);
  16.  } else if(product === "peanuts") {
  17.      price = Number(1.60);
  18.  } else {
  19.     console.log("Некъде има грешка батко!");
  20.  }
  21. }
  22.  
  23. if(city === "Plovdiv") {
  24.     if(product === "water") {
  25.     price = 0.70;
  26.     } else if(product === "coffee") {
  27.     price = 0.40;
  28.     } else if(product === "beer") {
  29.     price = 1.15;
  30.     } else if(product === "sweets") {
  31.     price = 1.30;
  32.     } else if(product === "peanuts") {
  33.     price = 1.50;
  34.     } else {
  35.        console.log("Некъде има грешка батко!");
  36.     }
  37.    }
  38.  
  39.    if(city === "Varna") {
  40.     if(product === "water") {
  41.     price = 0.70;
  42.     } else if(product === "coffee") {
  43.     price = 0.45;
  44.     } else if(product === "beer") {
  45.     price = 1.10;
  46.     } else if(product === "sweets") {
  47.     price = 1.35;
  48.     } else if(product === "peanuts") {
  49.     price = 1.55;
  50.     } else {
  51.        console.log("Некъде има грешка батко!");
  52.     }
  53.    }
  54.  
  55.    let finalSum = Number(price * quantity);
  56.    console.log(finalSum);
  57. }
Tags: programming
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement