Array

S

shannon

Hi,

Anybody got any suggestions about using two arrays. First i need to
ask the user their name and if their require a seat between 1and 5 or
between 6 and 10. I need to assign this information in two arrays.
Any suggestions. I have been working on this so far.
<script type="text/javascript">


var theArray = new Array(10);


//var sizeOfArray = parseInt(prompt("How many items will the array
have?", ""));


for(i=0; i<10; i++)
{

theArray = prompt( "Please enter your name");
}

for(i=0; i<theArray.length; i++)
{

document.writeln( "theArray[" + i + " ] = " + theArray + "<br />");
}
</script>
 
E

Evertjan.

shannon wrote on 19 nov 2005 in comp.lang.javascript:
Anybody got any suggestions about using two arrays. First i need to
ask the user their name and if their require a seat between 1and 5 or
between 6 and 10.
I need to assign this information in two arrays.

Why?
 
S

shannon

It is an assignment i'm working on and i'm not sure how to store user
information into an array. The full spec. the Reservation System
assignment already posted up yesterday. I don't expect the solution
just some help.
Here is another piece i'm working on but not sure what to do next.
SCRIPT LANGUAGE = "JavaScript">

var passengerName; // first string entered by user
var seatType; // second string entered by user
var classType;



passengerName = window.prompt( "Enter your name:", "0" );


seatType = window.prompt( "For First Class type 1 or 2 for
Economy:", "0" );


if (seatType == 1)
{
classType = "First Class";
}
else
{
classType = "Economy";
}

document.writeln( "<H1>Boarding Pass Information</H1>" );
document.writeln( "<TABLE BORDER = \"1\"" + "WIDTH = \"40%\">");


document.writeln( "<TR><TD>" + "<b>" +"NAME:" + "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + passengerName +
"</TD></TR>" );


document.writeln( "<TR><TD>" + "<b>" + "SEAT TYPE"+ "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + seatType+
"</TD></TR>" );


document.writeln( "<TR><TD>" + "<b>" + "CLASS TYPE"+ "</b>" +
"</TD></TR>" );


document.writeln( "<TR><TD>" + classType +
"</TD></TR>" );


document.writeln( "</TABLE>" );
</SCRIPT>
 
E

Evertjan.

shannon wrote on 19 nov 2005 in comp.lang.javascript:
[please do not toppost on usenet - corrected]
It is an assignment i'm working on and i'm not sure how to store user
information into an array. The full spec. the Reservation System
assignment already posted up yesterday. I don't expect the solution
just some help.

The questin was why two array's?


name = new Array()
seatchoice = new Array()
// no size values needed here


name[0] = "aName"
seatchoice[0] = "1to5"

name[1] = "otherName"
seatchoice[1] = "6to10"

etc.

===========

btw, I should have a look into how other people set up a html page:

1 Do not use document.write() where simple html suffices.
document.writeln() is not usefull, since you probably cannot see the
HTML resulting source anyway. However I would suggest not using write()
at all.

2 First finish the page and then ask for the user input,
preferably in a form to be submitted. Yo can submit to the same page.
using prompt() is not very user friendly, as they cannot correct during
the inputting of the total information.

3 I cannot see what you want to accomplish by putting the info in an
array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top