I have a simple JavaScript program that converts celsius to fahreinheit and vice versa. But one function does not work and returns NaN.
<script type="text/javascript">
function CtoF() {
c = parseInt(document.getElementById("celsiusTemp").value);
fah = c * (9 / 5) + 32;
document.getElementById("resC").innerHTML = fah;
}
function FtoC() {
f = parseInt(document.getElementById("celsiusTemp").value);
cel = (f - 32) * (5 / 2);
document.getElementById("resF").innerHTML = cel;
}
</script>
<body>
<form>
<p>Insert celsius temperatur:
<input type="text" id="celsiusTemp" />
<br>
</p>
<p>Insert fahrenheit temperatur:
<input type="text" id="fahreheitTemp" />
<br>
</p>
<input type="button" class="btn btn-success" onClick="CtoF()" Value="Calc Fahrenheit" />
<input type="button" class="btn btn-warning" onClick="FtoC()" Value="Calc Celsius" />
</form>
<br/>
<p>The Result is :
<br/>
<p>Result celsius to fahreinhet:</p><span id="resC"></span>
<p>Result fahreinhet to celsius:</p><span id="resF"></span>
</body>
Why do I get NaN when calculating celsius)
Thanks!!