Hello,
I’m new to Javascript, and I can’t figure out what is wrong with the following temperature conversion. When I enter 0 in to the celcius text box, the conversion for degrees Kelvin is wrong. It seems like an order of operations error, but I’m certain that they are correct.
The error is with this line:
form.kelvinbox.value = (form.celciusbox.value) + 273.15;
instead of adding the value of form.celciusbox.value (which is 0) to 273.15, it is combining the two as a number 0273.15. There is only one plus sign on my keyboard.
There is a similar error with degrees Kelvin when you enter a value in the Fahrenheit text box.
For reference 0 deg C = 273.15 K = 32 deg F
<html>
<head>
</head>
<body>
<script language=”javascript”>
function celciusconvert (form) {
form.fahrenheitbox.value = (form.celciusbox.value) * 9 / 5 + 32;
form.kelvinbox.value = (form.celciusbox.value) + 273.15;
}
function kelvinconvert (form) {
form.celciusbox.value = (form.kelvinbox.value) – 273.15;
form.fahrenheitbox.value = (form.kelvinbox.value)
}
function fahrenheitconvert (form) {
form.celciusbox.value = ((form.fahrenheitbox.value) – 32) * 5 / 9;
form.kelvinbox.value = ((form.fahrenheitbox.value) + 459.67)
}
</script>
<form>
Celsius: <input type=”text” name=”celciusbox” value=”” onkeyup=”celciusconvert(this.form)”><br />
Kelvin: <input type=”text” name=”kelvinbox” value=”” onkeyup=”kelvinconvert(this.form)”><br />
Fahrenheit: <input type=”text” name=”fahrenheitbox” value=”” onkeyup=”fahrenheitconvert(this.form)”><br />
<br />
<input type=”reset” name=”reset” value=”Reset”>
</form>
</body>
</html>