モル数: mol
モル数の計算式 \(モル = \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="weight" value="12">
<select id="order">
<option value="kg">kg</option>
<option value="g" selected>g</option>
<option value="mg">mg</option>
<option value="ug">ug</option>
<option value="ng">ng</option>
</select>
</p>
<p><button id="button">計算する</button></p>
<p></p>
<p>モル数:<span id="mol"> </span> <span id="mol_order"></span>mol</p>
<script>
$("button").on("click", function(){
let mw = $("#mw").val();
let da = $('#da').val();
let weight = $("#weight").val();
let order = $('#order').val();
let da_order
if(da == "kDa"){
da_order = 1000;
}else{
da_order = 1;
}
full_mw = mw * da_order;
let weight_order
if(order == "kg"){
weight_order = 1000;
}else if(order == "g"){
weight_order = 1;
}else if(order == "mg"){
weight_order = 10**(-3);
}else if(order == "ug"){
weight_order = 10**(-6);
}else if(order == "ng"){
weight_order = 10**(-9);
}
full_weight = weight * weight_order;
mol = full_weight / full_mw;
let mol_order = Math.floor(Math.log10(mol))
let mol_order_str
if(mol_order <= -12){
mol = mol * 10**(12);
mol_order_str = "p";
}else if(mol_order <= -9){
mol = mol * 10**(9);
mol_order_str = "n";
}else if(mol_order <= -6){
mol = mol * 10**(6);
mol_order_str = "u";
}else if(mol_order <= -3){
mol = mol * 10**(3);
mol_order_str = "m";
}else if(mol_order <= 0){
mol = mol;
mol_order_str = " ";
}else if(mol_order <= 3){
mol = mol * 10**(-3);
mol_order_str = "k";
}
console.log(mol, mol_order_str)
$("#mol").text(mol.toFixed(3));
$("#mol_order").text(mol_order_str);
})
</script>
コメント