JSFiddle - React, Tailwind, and code Playground

JavaScript

function Hamburger(size, stuffing) {


    if (size != Hamburger.SIZE_SMALL && size != Hamburger.SIZE_BIG) {
        throw new Error("Неправильный формат size " + size);
    }
    if (stuffing != Hamburger.STUFFING_CHEESE && stuffing != Hamburger.STUFFING_SALAD && stuffing != Hamburger.STUFFING_POTATOES) {
        throw new Error("Неправильный формат stuffing " + stuffing);
    }


    this._size = size;
    this._stuffing = stuffing;
    this._toppings = [];

    this.addTopping = function(topping) {
        if (topping != Hamburger.TOPPING_MAYO && topping != Hamburger.TOPPING_SAUSE) {
            throw new Error("Неправильный формат topping " + topping);
        }
        for (var i = 0; i < this._toppings.length; i++) {
            if (topping == this._toppings[i]) {
                throw new Error("Топинг уже добавлен");
            }
        }

        this._toppings.push(topping);
    }

    this.calculateCalories = function() {
        var calories = 0;
        if (this._size == Hamburger.SIZE_SMALL) {
            calories += 20;
        } else {
            calories += 40;
        }

        switch (this._stuffing) {
            case Hamburger.STUFFING_CHEESE:
                calories += 20
                break
            case Hamburger.STUFFING_SALAD:
                calories += 5
                break
            case Hamburger.STUFFING_POTATOES:
                calories += 10
                break
        }
        for (var i = 0; i < this._toppings.length; i++) {
            if (this._toppings[i] == Hamburger.TOPPING_MAYO) {
                calories += 5;
            }
        }
        return calories;
    }

    this.calculatePrice = function() {
        var price = 0;
        if (this._size == Hamburger.SIZE_SMALL) {
            price += 50;
        } else {
            price += 100;
        }

        switch (this._stuffing) {
            case Hamburger.STUFFING_CHEESE:
                price += 10
                break
            case...