I am creating a script that finds the average temperature after the "mixing" of two volumes. The variables are called: coldWeight
warmWeight
coldTemp
warmTemp
. The formula sounds:
However, my code here which works as long as I don't use decimal numbers two places.
function averagetemp() {
let coldWeight = document.getElementById('coldWeight').value;
let warmWeight = document.getElementById('warmWeight').value;
let coldTemp = document.getElementById('coldTemp').value;
let warmTemp = document.getElementById('warmTemp').value;
var html = (warmWeight *warmTemp +coldWeight *coldTemp )/(coldWeight +warmWeight );
var html = html.toFixed(2);
document.getElementById('result').innerHTML = html;
}
It displays NaN every time I have a decimal number in coldWeight
and warmWeight
. None of the others. To compensate for the str to float, I use step=0.01
in all of the input divs.