By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

Temp Conversion Program...Help please

P: n/a
nyy
Hello everybody on this group. I have this program that is supposed to
display a temp. conversion from fahrenheit to celsius, can anybody
kindly can tell me what is wrong? Thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Temperature Conversion</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
var fahrenheit = new Array();
var celcius = 0;
for (var i = 0; i <= 100; ++i) {
fahrenheit[i] = i;
}
for (var j=0, j<100, ++j) {
celcius = (fahrenheit[i] - 32) * .55
document.write(fahrenheit[i] + " degrees Fahrenheit is equal to "
+ celcius + celsius.<br />);
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
</body>
</html>

Sep 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

for (var i = 0; i <= 100; ++i) {

for (var j=0, j<100, ++j) {

notice the <= in the first line and the < in the second.

notice also that u dont need the array.

and also that you are using document.write in the head section, and not
in the body section.

--
[php/javascript/coldfusion/ajax stuff]
http://www.geocities.com/kyoosho/

Sep 21 '05 #2

P: n/a
nyy wrote:
Hello everybody on this group. I have this program that is supposed to
display a temp. conversion from fahrenheit to celsius, can anybody
kindly can tell me what is wrong? Thanks.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Temperature Conversion</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
Forget using HTML comments inside script elements, particularly if your
browser is interpreting this as genuine XHTML - in which case
document.write may cause you some heartache too.

But never mind...
var fahrenheit = new Array();
This array is not required.
var celcius = 0;


This variable is not needed. If the intention is to write conversions
for 0 to 100 degrees Celsius to Fahrenheit, then the following:

for (var i=0; i <= 100; ++i) {
document.write( i + ' degrees Celcius is equal to '
+ (Math.round(i*9/5 + 32))
+ ' degrees Fahrenheit.<br />'
);
}

should do the trick, unless the point of the exercise was to use an array?

[...]


--
Rob
Sep 21 '05 #3

P: n/a
nyy wrote in message news:11*********************@f14g2000cwb.googlegro ups.com...
Hello everybody on this group. I have this program that is supposed to
display a temp. conversion from fahrenheit to celsius, can anybody
kindly can tell me what is wrong? Thanks.
Hi nyy, this is King Sapingo, remember me ;-)

I have a few comments:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
why XHTML
<html>
<head>
<title>Temperature Conversion</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
as someone else mentioned in another post,
there are no /incompatible browsers/
(in other words, you don't need this,
unless you actually publish it as XML (XHTML)
then you need the <![CDATA[ definition)

anyway, back to your problem:
var fahrenheit = new Array();
var celcius = 0;
for (var i = 0; i <= 100; ++i) {
fahrenheit[i] = i;
}
for (var j=0, j<100, ++j) { ^ ^
for (init ; while;incr)
you also probably mean j<=100
since you said i<=100 earlier

for (var j=0; j<=100; ++j)
celcius = (fahrenheit[i] - 32) * .55 ^ ^
didn't you want j instead of i? and end the line with ";"
(you will be surprised about some of the results "* 0.55" yelds ;-)
document.write(fahrenheit[i] + " degrees Fahrenheit is equal to " ^
the same j instead of i?
+ celcius + celsius.<br />); ^^^^^^^^^^^^^^^
you probably want this in "quotes" }
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
</body>
</html>


HTH
Sep 22 '05 #4

P: n/a
JRS: In article <11*********************@f14g2000cwb.googlegroups. com>,
dated Wed, 21 Sep 2005 08:05:57, seen in news:comp.lang.javascript, nyy
<je****@yahoo.com> posted :
celcius = (fahrenheit[i] - 32) * .55


Your ".55" should be written "0.55". Javascript will understand either,
bur relying on a half-bare decimal dot is liable to lead to human error.
See, if you have access, IUPAP-25 / SUNAMCO 87-1.

The conversion factor is in fact not 0.55 but bigger.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.