John B.

asked • 10/08/14

how would i write a javascript code for a temperature convert?

heres the HTML file:
<!DOCTYPE html>
<title>Temperature Converter</title>
<script type="text/javascript" src="Week7.js"></script>
<p>Enter a Temperature to Convert in the field below and select the starting scale.</p>
<input type="text" name="txtTemp" id="txtTemp" placeholder="Enter a Temperature" />
<br />
<br />
<input type="radio" id="radFahrenheit" name="radTemp" checked/>Fahrenheit to Celcius
<input type="radio" id="radCelcius" name="radTemp"/>Celcius to Fahrenheit
<button onclick="ConvertTemp();">Convert</button>

<div id="divResults"></div>
Im probably way off on my code but ehh I'm just now learning so with time will come experience and other good things:
function ConvertTemp(){
var radFahrenheit = document.getElementById('radFahrenheit');
var radCelcius = document.getElementById('radCelcius');
var txtTemp = document.getElementById('txtTemp');
var divResults = document.getElementById('divResults');

radFahrenheit = (radCelcius * (9/5)) + 32;
divResults = radFahrenheit;
}else if(radC.checked){
radCelcius = (radFahrenheit -32) * (5 / 9);
divResults = radCelcius;
I really wish I could talk to my teacher to get guidance from him but it's fall break and this assignment is do before classes start back so I am hoping that you kind people can give me some guidance. Thank you also I know you don't have to help me at all but I really do appreciate those of you who will help me.

1 Expert Answer


Baljeet S. answered • 10/31/14

New to Wyzant

Professional Programmer/PHP/Mysql/HTML/Oracle Service Cloud

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.


Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.