473,909 Members | 4,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

loops

47 New Member
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 1432
Plater
7,872 Recognized Expert Expert
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 Recognized Expert Top Contributor
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 Recognized Expert Expert
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
ballygowanboy
47 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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="javas cript1.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
ballygowanboy
47 New Member
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 Recognized Expert Moderator Expert
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 Recognized Expert Expert
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
5121
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 we need to break once more... So maybe there should be an argument to break that is an int which is a number of loops to break. So it would default to 1 (or whatever means the current enclosing loop), not breaking any code...
15
6584
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
2146
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) { /* main bulk of code goes here */ } }
46
9959
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 already in a loop." Then he goes on to portray a contrived example that doesn't tell me under what conditions a nested loop might be favoured as a solution? i.e. what are nested loops useful for? What kinds of algorithms are served by nested loops?...
6
1717
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 < n) { ...
17
3067
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 counter within the loop declaration, for loops have always seemed to me to be about doing something a certain number of times, and not about iterating over an object. The reason for this distinction comes from the fact that I read a lot how...
10
3998
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 than 'while'? C: for(i=0; i<length; i++) python: while i < length:
2
2304
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 there instances that you must use a Do-while loops instead of a for loops or a while loop? or you can use any types of loops in any given problem?
3
2429
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 field they are fairly large. the net result is that when 60 or so results are reitreved the page size is 400kb! which takes too long to load. is there a way of shorterning this? freeing up the memory say, bcos what is actually displayed is not...
8
7275
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 <Boolean ExpressionThen Exit For Next If Not <Boolean ExpressionThen Exit For
0
11346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10538
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7248
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5938
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3357
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.