Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<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.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, color: 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.checkAdditive = function(additive) {
  if (Hamburger.additive[additive] === undefined) {
      throw new Hamburger.incorrectArgs("Несуществующий тип добавки!");
  }
  
  if (this.additives.additive !== undefined) {
    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.additives = {};
  
  Hamburger.checkAdditive(additive);
  
  this.additives.additive = additive;
};
Hamburger.prototype.calcPrice = function() {  /* метод рассчета суммы */
  this.price = Hamburger.type[this.size].price + Hamburger.filling[this.filling].price;
  
  if (this.additives !== undefined) {
    for (var nameAddi in this.additives) {
      this.price += Hamburger.additive[nameAddi].price;
    }
  }
  
  return this.price;
};
Hamburger.prototype.calcCalor = function() {     /*метод рассчета калорийности*/
  this.calor = Hamburger.type[this.size].calor + Hamburger.filling[this.filling].calor;
  
  if (this.additives !== undefined) {
    for (var nameAddi in this.additives) { 
      this.calor += Hamburger.additive[nameAddi].calor;
    }
  }
  
  return this.calor;
};
var order1 = new Hamburger();
console.log(1);
order1.makeSelection(Hamburger.SIZE_BIG, Hamburger.FILLING_SALAD);
order1.makeAdditive(Hamburger.ADDITIVE_SEASONING);
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

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers