因此,我想让我的程序自动计算例如1克水中有多少个水原子。我需要它来分解公式,因此再次使用水,程序可以分配变量,如下所示: 氢变氢= 2 var oxygen = 1
我不知道如何制作它,这样我的程序才能读取公式并像这样分配它。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 align="center">Chemistry</h1>
<h2 align="center">Mole Calculations</h2>
<p>What is the element's formula?</p>
<input type="text" id="formula" />
<p>Are you converting to grams(g), miligrams(mg), pounds(lb), particles(amu), or moles(m)</p>
<input type="text" id="convertingto" />
<p>What measurement are you converting from? Use the same rules listed above.</p>
<input type="text" id="convertingfrom" />
<p>How much of the measurement above do you have of the element?</p>
<input type="text" id="amountstart" />
<br>
<br>
<button type="button" id="getmoles">Get Values</button>
<script>
document.getElementById('getmoles').onclick = function() {
var formula = document.getElementById('formula').value;
var to = document.getElementById('convertingto').value;
var from = document.getElementById('convertingfrom').value;
var amount = document.getElementById('amountstart').value;
}
</script>
</body>
</html>