473,225 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

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.

Check out this article.
Jul 26 '07 #10

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

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
4
by: Dr. David Kirkby | last post by:
I have a program that loops through and changes all the elements on an array n times, so my code looks like this: for (n=1; n < n_max; ++n) for(i=imax; i >= 0; --i) { for(j=0 ; j < jmax; ++j) {...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
6
by: Scott Brady Drummonds | last post by:
Hi, everyone, I was in a code review a couple of days ago and noticed one of my coworkers never used for() loops. Instead, he would use while() loops such as the following: i = 0; while (i...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
2
by: bitong | last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.