Correct HTMLcode: <!DOCTYPEhtml>
<html>
<head>
<title>TemperatureConverter</title>
<scripttype="text/javascript"
src="temp_converter.js"></script>
</head>
<body>
<p>Entera Temperature to Convert in the field below and select the starting
scale.</p>
<inputtype="text" name="txtTemp" id="txtTemp"
placeholder="Enter a Temperature" />
<br />
<br />
<inputtype="radio" id="radFahrenheit" name="radTemp"
checked/>Fahrenheit to Celsius
<br/>
<br/>
<inputtype="radio" id="radCelsius"
name="radTemp"/>Celsius to Fahrenheit
<br/>
<br/>
<br/>
<br/>
<buttonname="btnConvert" id="btnConvert"
onClick="ConvertTemp();">Convert</button>
<br/>
<br/>
<divid="divResults"></div>
</body>
</html>
temp_converter.js (not changed) var temp;
var outputArea;
function ConvertTemp(){
temp =parseInt(document.getElementById('txtTemp').value);
outputArea = document.getElementById('divResults');
var radF = document.getElementById('radFahrenheit');
var radC = document.getElementById('radCelsius');
if(radF.checked){
//Call Fahrenheit to Celsius
FtoC(temp);
}else if(radC.checked){
//Call Celsius to Fahrenheit
CtoF(temp);
}
}
//Fahrenheit to Celsius
function FtoC(temp){
C = (temp - 32) * (5 / 9);
outputArea.innerHTML = temp + " in Fahrenheit is" + C + " in Celsius.";
}
//Celsius to Fahrenheit
function CtoF(temp){
F = (temp * (9 / 5)) + 32;
outputArea.innerHTML = temp + " in Celsius is" + F + " in Fahrenheit.";
}
Comments
Leave a comment