473,692 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

im a total NEWB i need a little help understanding this script..specifi c instances are noted.

<script language="JavaS cript">
<!-- hide me

var the_number = prompt("how many words (3-5 is good)?", "4");
var the_string = "";
var a_word;

for (loop = 0; loop < the_number; loop++)
{
line_number = loop + 1;
a_word = prompt("what's word " + line_number + "?","");
the_string = "word " + line_number + ": " + a_word + "<br>" +
the_string;
}
var new_window =
window.open("re verse.html","re verse","height= 400,width=400") ;
new_window.docu ment.writeln("< h1>In reverse</h1>");
new_window.docu ment.writeln(th e_string);

// show me -->
</script>
ok heres what i DONT get and it kinda screws upo the whole thing for
me.
for (loop = 0; loop < the_number; loop++) ok loop++ means loop = loop +1 so loop is now 1 <0+1=1>
{
line_number = loop + 1; at this point it ADDS 1 to loop which is as i said 1 making "line_numbe r" = 2 <1+1> yet thats NOT how it works. it puts the value as 1. take out the +1
part and it makes the line number 0 ...i just dont get this at all. i
started on this java tutorial thing today at 7am..... its now 2 45 am
I understand the majority of it up to here....
of coursethe_string = "word " + line_number + ": " + a_word + "<br>" + the_string; kinda throws me it seems like its saying the _string = "word 1 : apple"+"word 1 : apple"

but i suppose im being to literal. i am guessing this adds the
afformentioned value to itself so the _string DOESNT= "word 1 :
apple"+"word 1 : apple"it just = "word 1 : apple" and whatever the
next word is will be added to that so it will be the_string="wor d 2
:orange, word 1 :apple"
any help is appreciated. i like to understand not only HOW but WHY?!
cause i see what it does i just dont know WHY and that bugs the heck
outta me.
Jul 20 '05 #1
1 1724
In article <07************ *************** *****@4ax.com>, nightsaber <ni********@hot mail.com> writes:
for (loop = 0; loop < the_number; loop++)
{
line_number = loop + 1;
a_word = prompt("what's word " + line_number + "?","");
the_string = "word " + line_number + ": " + a_word + "<br>" + the_string;
} ok heres what i DONT get and it kinda screws upo the whole thing for
me.
for (loop = 0; loop < the_number; loop++) ok loop++ means loop = loop +1 so loop is now 1 <0+1=1>
This is what's called a "for loop". The three things in the for statement
are:
initializtion: loop = 0;
test: loop < the_number;
increment: loop++;

The way that a for loop works is:
1. Execute the initialization:
loop = 0;
2. Execute the contents of the loop
{
line_number = loop + 1;
a_word = prompt("what's word " + line_number + "?","");
the_string = "word " + line_number + ": " + a_word + "<br>" + the_string;
}
(Note that, at this point, the value of "loop" is zero.)
3. Execute the increment:
loop++;
(Only at this point does "loop" get set to one.)
4. Execute the test:
loop < the_number;
If the test is satisfied (IOW, if "loop" is less than "the_number "),
you go back to step 2, and the contents of the loop are again
executed.
line_number = loop + 1; at this point it ADDS 1 to loop which is as i said 1 making "line_numbe r" = 2 <1+1>


But, that addition doesn't happen until after the contents of the loop
have been executed.

--
Michael F. Stemper
#include <Standard_Discl aimer>
Give a man a fish, and you feed him for a day. Teach him how to fish,
and you can sell him equipment.

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2128
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
1
10811
by: beavenour | last post by:
I am looking for some help creating a more universal function out of this lame attempt at javascript. I have little experience with javascript and want to be able to universalize this function. So how do I change this script so that I can call any field or any number of fields to be totaled? For example - calculate(myfield01, myfield02) at one total field and calculate(myfield06, myfield08, myfield11) at another total field instead of...
3
1828
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to construct a checkbox array in a survey form where one of the choices is "No Preference" which is checked by default. If the victim chooses other than "No Preference", I'd like to uncheck
4
1695
by: javascript_noob12 | last post by:
Hi. I am trying to create a CGI script that will use Perl to read a text file to get a list of values, then turn that list into a menu on a website. The menu will be a form with a JavaScript "submit" function. . When someone selects a menu-item, the form will submit the value of that list-entry to another CGI page. The problem I'm encountering is that the script I've written submits every value of the form rather than the one specific...
5
5690
by: fwells11 | last post by:
Hi there. As you will see from my questions, I am an SQL newb. I dabble but never get to spend enough time to get proficient so base any feeedback on that basis please. This is all theoretical information at this point so I am also going to post this in a MySQL related group. I will create some designs and post back to the group if I get any feedback I can use. Problem: I would like to be able to keep a running percentage total in...
4
6369
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost (cost). Users can dynamically add rows to the table so I don't know how many rows might need to be calculated. I need to calculate the total (qty * cost) and put that number in a table cell (or read only input box). I also need to sum the...
29
2641
by: jaysherby | last post by:
I'm new at Python and I need a little advice. Part of the script I'm trying to write needs to be aware of all the files of a certain extension in the script's path and all sub-directories. Can someone set me on the right path to what modules and calls to use to do that? You'd think that it would be a fairly simple proposition, but I can't find examples anywhere. Thanks.
15
6166
klarae99
by: klarae99 | last post by:
I am working on an Inventory Database in Access 2003. I am working on a report that I could print when its time to file our State Sales Tax paperwork. The figures I need for this report are Total Sales(not including tax), the Amount of Sales Subject to Tax, and the Total Sales Including Tax, all gathered for a specific time period. I have a query (qrySalesTax) to find all sales within a specified date range that also calculates the Total...
0
8604
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9083
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...
0
8961
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8800
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
8801
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...
1
6459
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4324
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...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1957
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.