<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
function Hamburger() {
}
Hamburger.SIZE_SMALL = 'SMALL';
Hamburger.SIZE_BIG = 'BIG';
Hamburger.CHEESE = 'CHEESE';
Hamburger.SALAD = 'SALAD';
Hamburger.POTATO = 'POTATO';
Hamburger.SEASONING = 'SEASONING';
Hamburger.MAYO = 'MAYO';
Hamburger.type = {
SMALL: { price: 50, calor: 20 },
BIG: { price: 100, calor: 40 }
};
Hamburger.filling = {
CHEESE: { price: 10, calor: 20 },
SALAD: { price: 20, calor: 5 },
POTATO: { price: 15, calor: 10 }
};
Hamburger.additive = {
SEASONING: { price: 15, color: 0 },
MAYO: { price: 20, calor: 5 }
};
Hamburger.prototype.makeAddative = function(additive) { /*метод для добавления добавки*/
if (additive == Hamburger.SEASONING) {
this.addativePrice = Hamburger.additive[Hamburger.SEASONING].price;
this.addativeCalor = Hamburger.additive[Hamburger.SEASONING].calor;
return 'Добавка: приправа';
} else if (additive == Hamburger.MAYO) {
this.addativePrice = Hamburger.additive[Hamburger.MAYO].price;
this.addativeCalor = Hamburger.additive[Hamburger.MAYO].calor;
return 'Добавка: майонез';
}
};
Hamburger.prototype.calcPrice = function() { /*метод рассчета суммы*/
var selection = this.full;
var sumPrice = 0;
sumPrice = Hamburger.type[selection[0]].price + Hamburger.filling[selection[1]].price;
if (this.addativePrice) {
sumPrice += this.addativePrice;
}
this.sumPrice = sumPrice;
return this.sumPrice;
};
Hamburger.prototype.calcCalor = function() { /*метод рассчета калорийности*/
var selection = this.full;
var sumCalor = 0;
sumCalor = Hamburger.type[selection[0]].calor + Hamburger.filling[selection[1]].calor;
if (this.addativeCalor) {
sumCalor += this.addativeCalor;
}
this.sumCalor = sumCalor;
return this.sumCalor;
};
Hamburger.prototype.makeSelection = function(hamburger, filling) { /*метод для создания заказа*/
var full = [];
var text = 'Ваш заказ: ';
/*где-то здесь должна быть проверка на корректность заказа*/
if (hamburger == Hamburger.SIZE_SMALL) {
full.push(Hamburger.SIZE_SMALL);
text += 'маленький гамбургер, ';
} else if (hamburger == Hamburger.SIZE_BIG){
full.push(Hamburger.SIZE_BIG);
text += 'большой гамбургер, ';
}
if (filling == Hamburger.CHEESE) {
full.push(this.CHEESE);
text += 'сыр';
} else if (filling == Hamburger.SALAD) {
full.push(Hamburger.SALAD);
text += 'салат';
} else {
full.push(Hamburger.POTATO);
text += 'картошка';
}
this.full = full;
this.text = text;
return this.text;
};
var order1 = new Hamburger();
console.log(1);
console.log(order1.makeSelection(Hamburger.SIZE_BIG, Hamburger.SALAD));
console.log(order1.makeAddative(Hamburger.MAYO));
console.log('Стоимость(тугриков): ' + order1.calcPrice());
console.log('Калории: ' + order1.calcCalor());
/*var order2 = new Hamburger();
console.log(2);
console.log(order2.makeSelection(Hamburger.SIZE_SMALL, Hamburger.POTATO));
console.log('Стоимость(тугриков): ' + order2.calcPrice());
console.log('Калории: ' + order2.calcCalor());
var order3 = new Hamburger();
console.log(3);
console.log(order3.makeSelection(Hamburger.SIZE_BIG, Hamburger.SALAD));
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_BIG, Hamburger.SALAD));
var order5 = new Hamburger();
console.log(5);
console.log(order5.makeSelection(Hamburger.SIZE_MIDDLE, Hamburger.SALAD));
console.log('Стоимость(тугриков): ' + order5.calcPrice());
console.log('Калории: ' + order5.calcCalor());*/
Output
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. |