Hi. I am new to this site so I hope you will all be able to help me with my problem. I am just starting to learn JavaScript so any help/feedback would be greatly appreciated.
I have to make a form that if you put a temperature in a textbox (either Celsius or Fahrenheit) and you click on a button (To Celsius or To Fahrenheit) it will convert it to the corresponding temperature which will appear in another textbox.
I have gotten this far but am getting a NaN value in the coverted temperature
I have been trying to work this out for over a week so any help would be really appreciated.
My code is:
</form>
<!-- used to calculate the temperature conversion from Celcius to Farenheit and Farenheit to Celcius
!-->
<script>
function celcius()
{
document.getElementById("answers").value = parseFloat(document.getElementById("input").value) + Math.round(100/(212-32) * (this.value - 32 ));
}
function farenheit()
{
document.getElementById("answers").value = parseFloat(document.getElementById("input").value) + Math.round((212-32)/100 * this.value + 32);
}
</script>
<h1>Temperature Conversion Tool</h1>
<h3>Enter a value into the first box below, then click on what it is to be converted to
Temperature</h3>
<form name="temperature">
<input id="input" value="0" type="text">
<input id="answers" value="0" type="text">
<br>
<input value="To Celcius" onClick="celcius() " type="button">
<input value="To Farenheit" onClick="farenheit()
" type="button">
<input name="reset" value="Reset" type="reset"><br>
</form>