【ツール】分子量とモル数から質量を計算

  • URLをコピーしました!

質量 :      g

モル数の計算式 \(モル = \frac{質量}{分子量}\)

<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>

<p><label>分子量:</label><input type="Input" id="mw" value="12">
    <select id="da">
        <option value="Da" selected>Da</option>
        <option value="kDa">kDa</option>
    </select>
</p>
<p><label>モル数:</label><input type="Input" id="mol" value="1">
    <select id="order">
        <option value="mol" selected>mol</option>
        <option value="mmol">mmol</option>
        <option value="umol">umol</option>
        <option value="nmol">nmol</option>
    </select>
</p>
<p><button id="button">計算する</button></p>
<p></p>
<p>質量 :<span id="weight">     </span> <span id="weight_order"></span>g</p>
<script>
    $("button").on("click", function(){
        let mw = $("#mw").val();
        let da = $('#da').val();
        let mol = $("#mol").val();
        let order = $('#order').val();

        let da_order
        if(da == "kDa"){
            da_order = 1000;
        }else{
            da_order = 1;
        }
        full_mw = mw * da_order;

        let mol_order
        if(order == "mol"){
            mol_order = 1;
        }else if(order == "mmol"){
            mol_order = 10**(-3);
        }else if(order == "umol"){
            mol_order = 10**(-6);
        }else if(order == "nmol"){
            mol_order = 10**(-9);
        }
        full_mol = mol * mol_order;

        weight = full_mol * full_mw;
        
        let weight_order = Math.floor(Math.log10(weight))

        console.log(weight_order)

        let weight_order_str
        if(weight_order <= -9){
            weight = weight * 10**(12);
            weight_order_str = "p";
        }else if(weight_order <= -6){
            weight = weight * 10**(9);
            weight_order_str = "n";
        }else if(weight_order <= -3){
            weight = weight * 10**(6);
            weight_order_str = "u";
        }else if(weight_order <= 0){
            weight = weight * 10**(3);
            weight_order_str = "m";
        }else if(weight_order <= 3){
            weight = weight;
            weight_order_str = " ";
        }else if(weight_order <= 6){
            weight = weight * 10**(-3);
            weight_order_str = "k";
        }

        console.log(weight, weight_order_str)
        $("#weight").text(weight.toFixed(3));
        $("#weight_order").text(weight_order_str);
    })
</script>
よかったらシェアしてね!
  • URLをコピーしました!

コメント

コメントする

目次