473,225 Members | 1,283 Online

# loops

can anyone tell me where to beging with this one?

Write a program in Javascript which uses a while loop to output a conversion table for 1-100 degrees C to degrees F.

Where F= (C* 9/5) + 32
Jul 25 '07 #1
9 1394
Plater
7,872 Expert 4TB
This sounds like a homework question, and also not a very difficult one.
Look up to the FOR loop in javascript on a tutorial site and you should find all you need to know
Jul 25 '07 #2
epots9
1,351 Expert 1GB
can anyone tell me where to beging with this one?

Write a program in Javascript which uses a while loop to output a conversion table for 1-100 degrees C to degrees F.

Where F= (C* 9/5) + 32
y not use a forloop?

good luck
Jul 25 '07 #3
pbmods
5,821 Expert 4TB
y not use a forloop?
Never ask a question about homework. There is no good response, except for, "I want you to do it this way."

While loops better teach the fundamentals behind looping. When you think about it, a for loop is really just an efficient way of coding a while loop with a counter.

[EDIT: Ok, who did that? You know who you are.]
Jul 25 '07 #4
i wrote a simple php script, which i then had to turn into a javascript, it's not working.

i'm unsure when to put "var" in front of a variable in javascript.

can someone tell me what i'm doing wrong, thanks.

Expand|Select|Wrap|Line Numbers
1. <script language="javascript1.2">
2.
3. document.write("<b>Celcius to Farenheit</b><br>");
4.
5. function getF(x)
6.     {
7.     var convert = x * 1.8 + 32;
8.     return convert;
9.     }
10.
11.     var i=0;
12.
13.     while(i<=100) {
14.         result=getF(i);
15.         document.write "i - result <br>";
16.         i=i+1;
17.     }
18.
19. </script>
20.
Jul 26 '07 #5
iam_clint
1,208 Expert 1GB
this is homework isn't it????

Expand|Select|Wrap|Line Numbers
1. document.write "i - result <br>";
You had this line mostly correct, although its going to literally write i - result then a break

it needs to look something like this
Expand|Select|Wrap|Line Numbers
1. document.write(i - result+"<br>");
Jul 26 '07 #6
epots9
1,351 Expert 1GB
i wrote a simple php script, which i then had to turn into a javascript, it's not working.

i'm unsure when to put "var" in front of a variable in javascript.

can someone tell me what i'm doing wrong, thanks.

Expand|Select|Wrap|Line Numbers
1.
2. <script language="javascript1.2">
3.
4. document.write("<b>Celcius to Farenheit</b><br>");
5.
6. function getF(x)
7.     {
8.     var convert = x * 1.8 + 32;
9.     return convert;
10.     }
11.
12.     var i=0;
13.
14.     while(i<=100) {
15.         result=getF(i);
16.         document.write "i - result <br>";
17.         i=i+1;
18.     }
19.
20. </script>
without testing everything it looks good, but instead of
[html]
<script language="javascript1.2"></script>
[/html]
use
[html]
<script type="text/javascript"></script>
[/html]
info about script tag

and u should use
Expand|Select|Wrap|Line Numbers
1. var result=getF(i);
2. document.write(i - result+"<br>");
3.
test that out...

good luck
Jul 26 '07 #7
ok, almost working, but it's not writing the value of i

i'm just geting - result

-32
-32.8
-33.6
-34.4.................

Expand|Select|Wrap|Line Numbers
1. <script language="javascript1.2">
2.
3. document.write("<b>Celcius to Farenheit</b><br>");
4.
5. function getF(x)
6.     {
7.     var convert = x * 1.8 + 32;
8.     return convert;
9.     }
10.
11.     var i=0;
12.
13.     while(i<=100) {
14.         var result=getF(i);
15.         document.write(i - result+"<br>");
16.         i=i+1;
17.     }
18.
19. </script>
Jul 26 '07 #8
gits
5,390 Expert Mod 4TB
hi ballygowanboy,

please use the correct CODE tags when posting code ... and don't use textformating tags for it ... have a look here

kind regards
Jul 26 '07 #9
pbmods
5,821 Expert 4TB
Heya, ballygowanboy.