Квартално магазинче(1.Лаб: Вложени условни конструкции)
function solve(product, city, quantity) {
quantity = Number(quantity);
let price = 0;
if (city === "Sofia") {
switch (product) {
case "coffee":
price = .50;
break;
case "water":
price = .80;
break;
case "beer":
price = 1.20;
break;
case "sweets":
price = 1.45;
break;
case "peanuts":
price = 1.60;
break;
default:
break;
}
} else if (city === "Plovdiv") {
switch (product) {
case "coffee":
price = .40;
break;
case "water":
price = .70;
break;
case "beer":
price = 1.15;
break;
case "sweets":
price = 1.30;
break;
case "peanuts":
price = 1.50;
break;
default:
break;
}
} else if (city === "Varna") {
switch (product) {
case "coffee":
price = .45;
break;
case "water":
price = .70;
break;
case "beer":
price = 1.10;
break;
case "sweets":
price = 1.35;
break;
case "peanuts":
price = 1.55;
break;
default:
break;
}
}
let finalPrice = price * quantity;
console.log(finalPrice);
}
solve("coffee",
"Varna",
"2");
Благодаря за отговора.