JSFiddle - React, Tailwind, and code Playground
JavaScript
"use strict";
Hamburger.SIZE_SMALL = 'SMALL';
Hamburger.SIZE_BIG = 'BIG';
Hamburger.STUFFING_CHEESE = 'CHEESE';
Hamburger.STUFFING_SALADE = 'SALADE';
Hamburger.STUFFING_POTATO = 'POTATO';
Hamburger.TOPPING_MAYO = 'MAYO';
Hamburger.TOPPING_CONDIMENT = 'CONDIMENT';
function Hamburger(size, stuffing) {
this._hamburgerSizeEnum = [Hamburger.SIZE_SMALL, Hamburger.SIZE_BIG];
this._hamburgerStuffingEnum = [Hamburger.STUFFING_CHEESE, Hamburger.STUFFING_SALADE, Hamburger.STUFFING_POTATO];
this._hamburgerToppingEnum = [Hamburger.TOPPING_MAYO, Hamburger.TOPPING_CONDIMENT];
this._size;
this._stuffing;
this._toppings = [];
this._setSize(size);
this._setStuffing(stuffing);
}
Hamburger.prototype._setSize = function(size) {
var sizeIndex = this._hamburgerSizeEnum.indexOf(size);
if (sizeIndex === -1) {
throw new HamburgerException('Invalid size. Only ' + this._hamburgerSizeEnum.join`, ` + ' are available.');
}
this._size = this._hamburgerSizeEnum[sizeIndex];
}
Hamburger.prototype._setStuffing = function(stuffing) {
var stuffingIndex = this._hamburgerStuffingEnum.indexOf(stuffing);
if (stuffingIndex === -1) {
throw new HamburgerException('Invalid stuffing. Only ' + this._hamburgerStuffingEnum.join`, ` + ' are available.');
}
this._stuffing = this._hamburgerStuffingEnum[stuffingIndex];
}
Hamburger.prototype.addTopping = function(topping) {
var toppingIndex = this._hamburgerToppingEnum.indexOf(topping);
if (toppingIndex === -1) {
throw new HamburgerException('Invalid topping. Only ' + this_.hamburgerToppingEnum.join`, ` + ' are available.');
} else if (this._toppings[toppingIndex]) {
throw new HamburgerException('Duplicate topping: ' + this._getPriceCaloriesDescForConstant(topping).desc);
}
this._toppings.push(topping);
}
Hamburger.prototype._getPriceCaloriesDescForConstant = function(constant) {
switch (constant) {
case Hamburger.SIZE_SMALL:
return { price: 50, calories: 20 };
case...