<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
function Hamburger(size, filling) {
this.size = size;
this.filling = filling;
this.extended = [];
}
Hamburger.prototype = {
getCost: function() {
this.checkType(this.size);
this.checkType(this.filling);
return Hamburger.prices[this.size] + Hamburger.prices[this.filling] + this.getCostOfExtended();
},
getCalories: function() {
return Hamburger.calories[this.size] + Hamburger.calories[this.filling] + this.getCaloriesOfExtended();
},
addExtended: function(type) {
for (var i = 0; i < arguments.length; i++) {
this.extended.push(arguments[i]);
}
},
getCaloriesOfExtended: function() {
var caloriesSum = 0;
for (var n = 0; n < this.extended.length; n++) {
caloriesSum += Hamburger.calories[this.extended[n]];
}
return caloriesSum;
},
getCostOfExtended: function() {
var costSum = 0;
for (var m = 0; m < this.extended.length; m++) {
this.checkType(this.extended[m]);
if (this.extended[m] == this.extended[m - 1]) {
throw new Error('Одинаковые добавки');
} else {
costSum += Hamburger.prices[this.extended[m]];
}
}
return costSum;
},
checkType: function(arg) {
if (!(arg in Hamburger.prices)) {
throw new Error('Неверные данные');
}
},
constructor: Hamburger
};
Hamburger.TYPE_SMALL = 'small';
Hamburger.TYPE_BIG = 'big';
Hamburger.FILLING_CHEESE = 'cheese';
Hamburger.FILLING_SALAD = 'salad';
Hamburger.FILLING_POTATO = 'potato';
Hamburger.EXTENDED_SEASONING = 'seasoning';
Hamburger.EXTENDED_SAUCE = 'sauce';
Hamburger.prices = {};
Hamburger.prices[Hamburger.TYPE_SMALL] = 50;
Hamburger.prices[Hamburger.TYPE_BIG] = 100;
Hamburger.prices[Hamburger.FILLING_CHEESE] = 10;
Hamburger.prices[Hamburger.FILLING_SALAD] = 20;
Hamburger.prices[Hamburger.FILLING_POTATO] = 15;
Hamburger.prices[Hamburger.EXTENDED_SEASONING] = 15;
Hamburger.prices[Hamburger.EXTENDED_SAUCE] = 20;
Hamburger.calories = {};
Hamburger.calories[Hamburger.TYPE_SMALL] = 20;
Hamburger.calories[Hamburger.TYPE_BIG] = 40;
Hamburger.calories[Hamburger.FILLING_CHEESE] = 20;
Hamburger.calories[Hamburger.FILLING_SALAD] = 5;
Hamburger.calories[Hamburger.FILLING_POTATO] = 10;
Hamburger.calories[Hamburger.EXTENDED_SEASONING] = 0;
Hamburger.calories[Hamburger.EXTENDED_SAUCE] = 5;
var hamburger = new Hamburger(Hamburger.TYPE_SMALL, Hamburger.FILLING_CHEESE);
hamburger.addExtended(Hamburger.EXTENDED_SEASONING, Hamburger.EXTENDED_SAUCE);
console.log(hamburger.getCost(), hamburger.getCalories());
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. |