fahrenheit conversion & celsius conversion

admin

Administrator
Staff member
can anyone tell me what is wrong with the code on this it is giving me the same answers for both entries. Thanks here it is:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Web Programming 1</title>
<script language="JavaScript">
function temperatureConversion()
{
var originalCelsius = 0;
var convertedFahrenheit = 0;
var response = prompt ("Enter a number representing " + " a Celsius temp. I will convert it " + " to its Fahrenheit equivalent and " + " display it in the status bar at the bottom " + " of the screen", "0");
originalCelsius = parseFloat (response);
if (isNaN (originalCelsius))
{
window.defaultStatus = ("Non-numeric value entered!");
}
else
{
convertedFahrenheit = 9 / 5 * (originalCelsius + 32);
window.defaultStatus = (originalCelsius + "degrees Celsius = " + convertedFahrenheit + " degrees Fahrenheit");
}
}
function temperatureConversion()
{

var originalFahrenheit = 0;
var convertedCelsius = 0;

var response = prompt ("Enter a number representing " + " a Fahrenheit temp. I will convert it " + " to its Celsius equivalent and " + " display it in the status bar at the bottom " + " of the screen", "0");
originalFahrenheit = parseFloat (response);
if (isNaN (originalFahrenheit))
{
window.defaultStatus = ("Non-numeric value entered!");
}
else
{
convertedCelsius =5 / 9 * (originalFahrenheit - 32);
window.defaultStatus = (originalFahrenheit + "degrees Fahrenheit = " + convertedCelsius + " degrees Celsius");
}
}
</script>
</head>

<pre>
<input type = "button" name = "temp"
value = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"Convert Fahrenheit Temp to Celsius Equivalent"
onClick = "temperatureConversion()">
</pre>

<body bgcolor="white">
<form name="myform">

<pre>
<input type = "button" name = "temp"
value = "Convert Celsius Temp to Fahrenheit Equivalent"
onClick = "temperatureConversion()">

</pre>
</form>

</body>

</html>
 
Back
Top