Created
April 19, 2015 15:12
-
-
Save anonymous/f96bcb86067a080ed8c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Hamburger(size, filling, extra){ | |
size = size.toUpperCase(); | |
filling = filling.toUpperCase(); | |
extra = (extra!==null) ? extra.toUpperCase() : extra; | |
this.CONSTANTS = { | |
SMALL: {price: 50, calorie: 20}, | |
BIG: {price: 100, calorie: 40}, | |
CHEESE: {price: 10, calorie: 20}, | |
SALAD: {price: 20, calorie: 5}, | |
POTATOES: {price: 15, calorie: 10}, | |
SAUCE: {price: 20, calorie: 5}, | |
SPICE: {price: 15, calorie: 0} | |
}; | |
this.size = size; | |
this.filling = filling; | |
this.extra = extra; | |
} | |
Hamburger.prototype.calculate = function(){ | |
try{ | |
if(this.extra!=null){ | |
var price = this.CONSTANTS[this.size].price + this.CONSTANTS[this.filling].price | |
+ this.CONSTANTS[this.extra].price; | |
var calorie = this.CONSTANTS[this.size].calorie | |
+ this.CONSTANTS[this.filling].calorie | |
+ this.CONSTANTS[this.extra].calorie; | |
}else{ | |
var price = this.CONSTANTS[this.size].price + this.CONSTANTS[this.filling].price; | |
var calorie = this.CONSTANTS[this.size].calorie + this.CONSTANTS[this.filling].calorie; | |
} | |
return {'price': price, 'calorie': calorie}; | |
}catch(e){ | |
console.log('Вы ввели неправильный тип гамбургера, начинки или добавки.'); | |
} | |
}; | |
var hamburger = new Hamburger('big', 'salad', 'sauce'); | |
console.log(hamburger.calculate()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment