/    Sign up×
Community /Pin to ProfileBookmark

fahrenheit conversion & celsius conversion

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 = “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>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@havikMar 27.2003 — The problem is that the function: temperatureConversion()

is defined twice. Try change the name of these functions. I tryed celtofar() and fartocel() and it worked.

Here it is, that's all that needed to be changed

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Web Programming 1</title>

<script language="JavaScript">

function celtofar()

{

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 fartocel()

{

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 = "Convert Fahrenheit Temp to Celsius Equivalent"

onClick = "fartocel()">

</pre>

<body bgcolor="white">

<form name="myform">

<pre>

<input type = "button" name = "temp"

value = "Convert Celsius Temp to Fahrenheit Equivalent"

onClick = "celtofar()">

</pre>

</form>

</body>

</html>
×

Success!

Help @fisk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...