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.CHEESE = 'cheese';
Hamburger.SALAD = 'salad';
Hamburger.POTATO = 'potato';
Hamburger.properties = {
  small: { price: 50, calor: 20 },
  big: { price: 100, calor: 40 },
  cheese: {  price: 10, calor: 20 },
  salad: { price: 20, calor: 5 },
  potato: { price: 15, calor: 10 }
};
var SIZE_SMALL = 'small',
    SIZE_BIG = 'big',
    CHEESE = 'cheese',
    SALAD = 'salad',
    POTATO = 'potato';
Hamburger.prototype.calcPrice = function() {
  if (!this.full) {
    return 'Ошибка: Вы не сделали заказ';
  }
  
  var selection = this.full;
  var sumPrice = 0;
  
  for (var i = 0; i < selection.length; i++) {
    sumPrice += Hamburger.properties[selection[i]].price;
  }
  
  this.sumPrice = sumPrice;
  
  return this.sumPrice;
};
Hamburger.prototype.calcCalor = function() {
  if (!this.full) {
    return 'Ошибка: Вы не сделали заказ';
  }
  
  var selection = this.full;
  var sumCalor = 0;
  
  for (var i = 0; i < selection.length; i++) {
    sumCalor += Hamburger.properties[selection[i]].calor;
  }
  
  this.sumCalor = sumCalor;
  
  return this.sumCalor;
};
Hamburger.prototype.makeSelection = function(hamburger, filling) {
  var full = [];
  var text = 'Ваш заказ: ';
  
  if (hamburger == SIZE_SMALL) {
    full.push(SIZE_SMALL);
    text += 'маленький гамбургер, ';
  } else if (hamburger == SIZE_BIG){
    full.push(SIZE_BIG);
    text += 'большой гамбургер, ';
  }
  
  if (filling == CHEESE) {
    full.push(CHEESE);
    text += 'сыр';
  } else if (filling == SALAD) {
    full.push(SALAD);
    text += 'салат';
  } else {
    full.push(POTATO);
    text += 'картошка';
  }
  
  this.full = full;
  this.text = text;
  
  return this.text;
};
var order1 = new Hamburger();
console.log(1);
console.log(order1.makeSelection(SIZE_BIG, SALAD));
console.log('Стоимость(тугриков): ' + order1.calcPrice());
console.log('Калории: ' + order1.calcCalor());
var order2 = new Hamburger();
console.log(2);
console.log(order2.makeSelection(SIZE_SMALL, POTATO));
console.log('Стоимость(тугриков): ' + order2.calcPrice());
console.log('Калории: ' + order2.calcCalor());
var order3 = new Hamburger();
console.log(3);
console.log(order3.makeSelection(SIZE_BIG, 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(SIZE_BIG, SALAD));
var order5 = new Hamburger();
console.log(5);
console.log(order5.makeSelection(SIZE_MIDDLE, 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