JSFiddle - React, Tailwind, and code Playground
JavaScript
function Gamburger(size, firstFilling) {
this.recipe = {};
if (size == "big") {
this.size = "big";
this.cost = 100;
this.calorificValue = 40;
} else if (size == "small") {
this.size = "small";
this.cost = 50;
this.calorificValue = 20;
} else {
return console.log("неверный размер");
}
switch (firstFilling) {
case "cheese":
this.addCheese()
break
case "salad":
this.addSalad()
break
case "potato":
this.addPotato()
break
case "seasoning":
this.addSeasoning()
break
case "mayonnaise":
this.addMayonnaise()
break
default: return "неправильный первый игридиент"
break
}
}
Gamburger.prototype = {
addCheese: function(obj) {
this.recipe.cheese = true;
this.cost += 10;
this.calorificValue += 20;
},
addSalad: function(obj) {
this.recipe.salad = true;
this.cost += 20;
this.calorificValue += 5;
},
addPotato: function(obj) {
this.recipe.potato = true;
this.cost += 15;
this.calorificValue += 10;
},
addSeasoning: function(obj) {
this.recipe.seasoning = true;
this.cost += 15;
},
addMayonnaise: function(obj) {
this.recipe.mayonnaise = true;
this.cost += 20;
this.calorificValue += 5;
}
}
var gam = new Gamburger("small","cheese");
gam.addPotato();