function Gamburger(size, stuff, spiсes, mayo) {
var SIZE = {
small: {
cost: 50,
cal: 20
},
big: {
cost: 100,
cal: 40
}
};
var STUFF = {
cheese: {
cost: 10,
cal: 20
},
salad: {
cost: 20,
cal: 5
},
potato: {
cost: 15,
cal: 10
}
};
var SPICES = {
cost: 15,
cal: 0
};
var MAYO = {
cost: 20,
cal: 5
};
var size = size.toLowerCase();
var stuff = stuff.toLowerCase();
//var spiсes = spiсes || undefined;
//var mayo = mayo || undefined;
function calc(value) { //calculate total cost OR total cals
if (!checkValues()) return;
var result = SIZE[size][value] + STUFF[stuff][value];
if (spiсes) result += SPICES[value];
if (mayo) result += MAYO[value];
return result;
}
function checkValues() { //checking of arguments
var checked = true;
if (!(size in SIZE)) {
console.log('Нет такого размера!');
checked = false;
}
if (!(stuff in STUFF)) {
console.log('Нет такой начинки!');
checked = false;
}
return checked;
}
this.getCost = function() {
return calc('cost');
}
this.getCals = function() {
return calc('cal');
}
}
var gamburger = new Gamburger('Small', 'salad', false, true);
console.log(gamburger.getCost() + " " + gamburger.getCals());
CiAgZnVuY3Rpb24gR2FtYnVyZ2VyKHNpemUsIHN0dWZmLCBzcGnRgWVzLCBtYXlvKSB7CiAgICB2YXIgU0laRSA9IHsKICAgICAgc21hbGw6IHsKICAgICAgICBjb3N0OiA1MCwKICAgICAgICBjYWw6IDIwCiAgICAgIH0sCiAgICAgIGJpZzogewogICAgICAgIGNvc3Q6IDEwMCwKICAgICAgICBjYWw6IDQwCiAgICAgIH0KICAgIH07CgogICAgdmFyIFNUVUZGID0gewogICAgICBjaGVlc2U6IHsKICAgICAgICBjb3N0OiAxMCwKICAgICAgICBjYWw6IDIwCiAgICAgIH0sCiAgICAgIHNhbGFkOiB7CiAgICAgICAgY29zdDogMjAsCiAgICAgICAgY2FsOiA1CiAgICAgIH0sCiAgICAgIHBvdGF0bzogewogICAgICAgIGNvc3Q6IDE1LAogICAgICAgIGNhbDogMTAKICAgICAgfQogICAgfTsKCiAgICB2YXIgU1BJQ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