473,550 Members | 2,911 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 1715
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
2118
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...
1
10806
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...
3
1818
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...
4
1686
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...
5
5679
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...
4
6355
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...
29
2617
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...
15
6153
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...
0
7487
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7758
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. ...
1
7517
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...
0
7844
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...
0
6098
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...
1
5401
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...
0
3530
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...
1
1978
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
0
800
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...

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.