469,315 Members | 1,565 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

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 1157
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.

Check out this article.
Jul 26 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Oleg Leschov | last post: by
15 posts views Thread by JustSomeGuy | last post: by
4 posts views Thread by Dr. David Kirkby | last post: by
46 posts views Thread by Neptune | last post: by
6 posts views Thread by Scott Brady Drummonds | last post: by
17 posts views Thread by John Salerno | last post: by
10 posts views Thread by Putty | last post: by
2 posts views Thread by bitong | last post: by
3 posts views Thread by monomaniac21 | last post: by
8 posts views Thread by Nathan Sokalski | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.