var little = { name: "Маленький", price: 50 , calories: 20 };
var big = { name: "Большой", price: 100 , calories: 40 };
var cheese = { name: "Сыр", price: 10 , calories: 20 };
var salad = { name: "Салат", price: 20 , calories: 5 };
var potato = { name: "Картофель", price: 15 , calories: 10 };
var sause = { name: "Приправа", price: 15 , calories: 0 };
var mayo = { name: "Майонез", price: 20 , calories: 5 };
function calculation(sort, stuffing, sause, mayo) {
var price = 0;
var calories = 0;
var arr = [];
switch (sort) {
case little:
price += 50;
calories += 20;
break
case big:
price += 100;
calories += 40;
break
default:
arr.push("Ошибка с выбором размера гамбургера");
return arr;
}
switch (stuffing) {
case cheese:
price += 10;
calories += 20;
break
case salad:
price += 20;
calories += 5;
break
case potato:
price += 15;
calories += 10;
break
default:
arr.push('Ошибка с выбором начинки гамбургера');
return arr;
}
if (sause) { //к примеру через промпт спросить, ответ true или false
price += 15;
calories += 0;
};
if (mayo) {
price += 20;
calories += 5;
};
arr.push(price);
arr.push(calories);
return arr;
}
console.log(calculation(big, salad, true, true));
dmFyIGxpdHRsZSA9IHsgbmFtZTogItCc0LDQu9C10L3RjNC60LjQuSIsIHByaWNlOiA1MCAsIGNhbG9yaWVzOiAyMCB9Owp2YXIgYmlnID0geyBuYW1lOiAi0JHQvtC70YzRiNC+0LkiLCBwcmljZTogMTAwICwgY2Fsb3JpZXM6IDQwIH07Cgp2YXIgY2hlZXNlID0geyBuYW1lOiAi0KHRi9GAIiwgcHJpY2U6IDEwICwgY2Fsb3JpZXM6IDIwIH07CnZhciBzYWxhZCA9IHsgbmFtZTogItCh0LDQu9Cw0YIiLCBwcmljZTogMjAgLCBjYWxvcmllczogNSB9OyAKdmFyIHBvdGF0byA9IHsgbmFtZTogItCa0LDRgNGC0L7RhNC10LvRjCIsIHByaWNlOiAxNSAsIGNhbG9yaWVzOiAxMCB9OwoKdmFyIHNhdXNlID0geyBuYW1lOiAi0J/RgNC40L/RgNCw0LLQsCIsIHByaWNlOiAxNSAsIGNhbG9yaWVzOiAwIH07CnZhci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