Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping and Arrays again 1

Status
Not open for further replies.

tnbrwneyez

Programmer
Oct 2, 2004
19
US
I have a script that I need to have code set to only allow 10 names. What do I need to add to this script?

<html>
<head>
<title>Loops Example</title>
</head>

<body>
<h1>Loop Example</h1>

<Script LANGUAGE="JavaScript1.2" type="text/javascript1.2">
names = new Array();
i=0;
do {
next=window.prompt("Enter the Next Name", "");
if (next > "") names =next;
i=i+1;
}
while (next > "");
document.write("<h2>" + (names.length) + " names entered. </h2>");
document.write("<ol>");
names.sort();
for (i in names){
document.write("<li>" + names + "<br>");
}

document.write("</ol>");
</script>
</body>
</html>


Thanks!!
 
Throw this if statement in some where inside your do loop
Code:
if (names.length>9) {break}
Matt
 
Thank you so much! It worked perfectly. I need you to be my instructor instead of the one that I have!!


Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top