JSFiddle - React, Tailwind, and code Playground

by TekVanDo

HTML

<div id="selectors">
    <select name="" id="town">
        <option value="Moskow">moscow</option>
    </select>
    <input type="text" id="weight">
    <input type="text" id="volume">
</div>
<button id="sum">sum</button>
<div id="c"></div>

JavaScript

var data = {
    Moskow: {
        name: "Москва",
        weight: {
            less200: {
                name: "до 200 кг",
                price: 6.5,
                less:200,
                more:0
            },
            more200Less1000: {
                name: "201-1000кг",
                more:201,
                less:1000,
                price: 6.3
            }
        },
        volume: {
            less9: {
                name: "до0.9м3",
                price: 1430,
                less:0.9,
                more:0
            },
            more9Less454: {
                name: "до0.9м3",
                price: 1386,
                less:4.54,
                more:0.91
            }
        }
    }
}

$(document).ready(function(){
    $("#sum").click(function(){
        var weight =$("#weight").val();
        var volume =$("#volume").val();
        if(weight != ""){
            var currentTown = data[$("#town").val()];
            var weightPrice = 0;           
            $.each(currentTown.weight,function(item,val){               
                if(weight <= val.less &&  weight > val.more){
                    weightPrice = val.price;
                }
            });           
            if(weightPrice != 0){
                $("#c").text(weightPrice*weight);
            }else{
                $("#c").text("нихуя не найдено");
            }
        }else if(volume != ""){
            var currentTown = data[$("#town").val()];
            var volumePrice = 0;
           
            $.each(currentTown.volume,function(item,val){
                if(volume <= val.less &&  volume > val.more){
                    volumePrice = val.price;
                }
            });
            
            if(volumePrice != 0){
                $("#c").text(volumePrice*volume);
            }else{
                $("#c").text("нихуя не найдено");
            }
        };
    });
});