Готовим пиццу!

by Anastasia Sharko

HTML

<title>Готовим пиццу!</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
  <body>
<h1>Cooking pizza!</h1>
<p>Choose receipt:</p>
<select class="js-choose-recipe">
    <option value="none">not selected</option>
</select>

<p class="js-choose" data-id="choose">Выбрано:</p>
<p>
<div>Рецепт</div>
<div class="js-chosen-recipe">Ничего не выбрано</div>
<div class='js-ingridients-title'>Ингридиенты</div>
<div class="js-ingridients"></div>
<div>Вес</div>
<div class="js-chosen-recipe-weight"></div>
<div>Дополнительные ингридиенты</div>
<ul>
    <li>Пока ничего не выбрано</li>
</ul>
</p>

</body>

JavaScript

Object.prototype.values = function(obj) {
    var keys = Object.keys(obj)
    return keys.map(function(key) {
        return obj[key]
    })
}

var INGRIDIENTS = {
    'cheese': {
        name: 'cheese',
        weight: 50,
        calories: 50,
        cost: 0.5
    },
    'sauce': {
        name: 'sauce',
        weight: 10,
        calories: 20,
        cost: 0.5
    },
    'mozzarela': {
        name: 'mozzarela',
        weight: 25,
        calories: 25,
        cost: 0.7
    },
    'camamber': {
        name: 'camamber',
        weight: 25,
        calories: 25,
        cost: 0.8
    },
    'feta': {
        name: 'feta',
        weight: 25,
        calories: 25,
        cost: 0.9
    },
    'peperoni': {
        name: 'peperoni',
        weight: 20,
        calories: 20,
        cost: 1.0
    }
}
function Pizza(recipe) {
    // правила создания объекта - его инициализация
    // this который доступен в этой функции - это новый объект, который будет создан если функцию вызвать с new
    this.base = recipe.base
    this.ingridients = recipe.ingridients
}

Pizza.prototype = { // or Object.create
    getWeight: function() { // 'эта функция называется метод объекта
        // this такой же как в функции-конструкторе
        // мы можем из него брать любые свойства
        var ingridientWeights = this.ingridients
            .map(function(el) {
                return el.weight
            })

        var allIngridientsWeight = ingridientWeights.reduce(function(sum, cur) {
            return sum + cur
        }, this.base.weight)
        return allIngridientsWeight
    },
    getCalories: function() {
        return this.calories
    },
      getCost: function() {
      var ingridientCost = this.ingridients
      .map(function(el) {
        return el.cost
   })
			
      var allIngridientsCost = ingridientCost.reduce(function(sum, cur) {
        return sum + cur
      }, this.base.cost)
     if (allIngridientsCost >= 30){
     	console.log('cost',...