<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
function Hamburger() {
this.additives = [];
}
Hamburger.SIZE_SMALL = 'SMALL';
Hamburger.SIZE_BIG = 'BIG';
Hamburger.FILLING_CHEESE = 'CHEESE';
Hamburger.FILLING_SALAD = 'SALAD';
Hamburger.FILLING_POTATO = 'POTATO';
Hamburger.ADDITIVE_SEASONING = 'SEASONING';
Hamburger.ADDITIVE_MAYO = 'MAYO';
Hamburger.type = {};
Hamburger.filling = {};
Hamburger.additive = {};
Hamburger.type[Hamburger.SIZE_SMALL] = { name: 'МАЛЕНЬКИЙ', price: 50, calor: 20 };
Hamburger.type[Hamburger.SIZE_BIG] = { name: 'БОЛЬШОЙ', price: 100, calor: 40 };
Hamburger.filling[Hamburger.FILLING_CHEESE] = { name: 'СЫР', price: 10, calor: 20 };
Hamburger.filling[Hamburger.FILLING_SALAD] = { name: 'САЛАТ', price: 20, calor: 5 };
Hamburger.filling[Hamburger.FILLING_POTATO] = { name: 'КАРТОШКА', price: 15, calor: 10 };
Hamburger.additive[Hamburger.ADDITIVE_SEASONING] = { name: 'ПРИПРАВА', price: 15, calor: 0 };
Hamburger.additive[Hamburger.ADDITIVE_MAYO] = { name: 'МАЙОНЕЗ', price: 20, calor: 5 };
Hamburger.incorrectArgs = function(message) {
this.message = message;
};
Hamburger.checkSize = function(size) {
if (!Hamburger.type[size]) {
throw new Hamburger.incorrectArgs("Несуществующий тип гамбургера!");
}
};
Hamburger.checkFilling = function(filling) {
if (!Hamburger.filling[filling]) {
throw new Hamburger.incorrectArgs("Несуществующая начинка!");
}
};
Hamburger.prototype.checkAdditive = function(additive) {
if (Hamburger.additive[additive] === undefined) {
throw new Hamburger.incorrectArgs("Несуществующий тип добавки!");
}
for (var i = 0; i < this.additives.length; i++) {
if (this.additives[i] == additive) {
throw new Hamburger.incorrectArgs("Повторная добавка запрещена!");
}
}
};
Hamburger.checkSizeAndFilling = function() {
if (!this.size && !this.filling) {
throw new Hamburger.incorrectArgs("Размер или начинка не заданы!");
}
}
Hamburger.prototype.makeSelection = function(size, filling) { /* метод для создания заказа */
Hamburger.checkSize(size);
Hamburger.checkFilling(filling);
this.size = size;
this.filling = filling;
};
Hamburger.prototype.makeAdditive = function(additive) { /*Добавка*/
this.checkAdditive(additive);
this.additives.push(additive);
};
Hamburger.prototype.calcPrice = function() { /* метод рассчета суммы */
Hamburger.checkSizeAndFilling();
this.price = Hamburger.type[this.size].price + Hamburger.filling[this.filling].price;
if (this.additives.length > 0) {
for (var i = 0; i < this.additives.length; i++) {
this.price += Hamburger.additive[this.additives[i]].price;
}
}
return this.price;
};
Hamburger.prototype.calcCalor = function() { /*метод рассчета калорийности*/
Hamburger.checkSizeAndFilling();
this.calor = Hamburger.type[this.size].calor + Hamburger.filling[this.filling].calor;
if (this.additives.length > 0) {
for (var i = 0; i < this.additives.length; i++) {
this.calor += Hamburger.additive[this.additives[i]].calor;
}
}
return this.calor;
};
var order1 = new Hamburger();
console.log(1);
order1.makeSelection(Hamburger.SIZE_BIG, Hamburger.FILLING_SALAD);
order1.makeAdditive(Hamburger.ADDITIVE_SEASONING);
order1.makeAdditive(Hamburger.ADDITIVE_MAYO);
console.log(order1.calcPrice());
console.log(order1.calcCalor());
/*var order2 = new Hamburger();
console.log(2);
console.log(order2.makeSelection(Hamburger.SIZE_SMALL, Hamburger.FILLING_POTATO));
console.log(order2.calcPrice());
console.log(order2.calcCalor());
var order3 = new Hamburger();
console.log(3);
console.log(order3.makeSelection(Hamburger.SIZE_BIG, Hamburger.FILLING_POTATO));
console.log(makeAdditive(Hamburger.ADDATIVE_SEASONING));
console.log(order3.calcPrice());
console.log(order3.calcCalor());
var order4 = new Hamburger();
console.log(4);
console.log(order4.calcPrice());
console.log(order4.calcCalor());
console.log(order4.makeSelection(Hamburger.SIZE_SMALL, Hamburger.FILLING_SALAD, Hamburger.ADDITIVE_MUSTARD));
var order5 = new Hamburger();
console.log(5);
console.log(order5.makeSelection(Hamburger.SIZE_MIDDLE, Hamburger.FILLING_SALAD));
console.log(order5.calcPrice());
console.log(order5.calcCalor());*/
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |