Hamburger.SIZE_BIG_PRICE = 100;
Hamburger.SIZE_BIG_CALORIC = 40;
Hamburger.SIZE_SMALL_PRICE = 50;
Hamburger.SIZE_SMALL_CALORIC = 20;
Hamburger.STUFFING_CHEESE_PRICE = 10;
Hamburger.STUFFING_CHEESE_CALORIC = 20;
Hamburger.STUFFING_SALAD_PRICE = 20;
Hamburger.STUFFING_SALAD_CALORIC = 5;
Hamburger.STUFFING_POTATOES_PRICE = 15;
Hamburger.STUFFING_POTATOES_CALORIC = 10;
Hamburger.TOPPING_SAUCE_PRICE = 15;
Hamburger.TOPPING_SAUCE_CALORIC = 0;
Hamburger.TOPPING_MAYO_PRICE = 20;
Hamburger.TOPPING_MAYO_CALORIC = 5;
function Hamburger(size_price, size_caloric, stuffing_price, stuffing_caloric) {
var price = size_price + stuffing_price;
var caloric = size_caloric + stuffing_caloric;
this.addTopping = function (topping_price, topping_caloric) {
price += topping_price;
caloric += topping_caloric;
}
this.calculateCalories = function () {
return caloric;
}
this.calculatePrice = function () {
return price;
}
}
// маленький гамбургер с начинкой из сыра
var hamburger = new Hamburger(Hamburger.SIZE_SMALL_PRICE, Hamburger.SIZE_SMALL_CALORIC, Hamburger.STUFFING_CHEESE_PRICE, Hamburger.STUFFING_CHEESE_CALORIC);
// добавка из майонеза
hamburger.addTopping(Hamburger.TOPPING_MAYO_PRICE, Hamburger.TOPPING_MAYO_CALORIC);
// спросим сколько там калорий
console.log("Calories: %f", hamburger.calculateCalories());
// сколько стоит
console.log("Price: %f", hamburger.calculatePrice());
// я тут передумал и решил добавить еще приправу
hamburger.addTopping(Hamburger.TOPPING_SAUCE_PRICE, Hamburger.TOPPING_SAUCE_CALORIC);
// А сколько теперь стоит?
console.log("Price with sauce: %f", hamburger.calculatePrice());