PDA

View Full Version : simple array populated by a prompt


Kevin
01-23-2003, 12:41 AM
Trying to remember how to populate an array() using the while loop and the prompt().

Been playing around with this for some time and still keep getting the error about the array() being undefined. What I need is an array of indeterminate length. Ergo user defined length.

What I have at present is:

function FillArray()
{
var Produce = prompt ("Please enter your favorite fruit?", "apple");
while (Produce)
{
var fruit = new array();
for (i = 0; ; i++)
{
var Produce = prompt ("Please enter your favorite fruit?", "apple" );
fruit[i] = Produce;
alert (fruit[0]);
}
}
}

The end result will be an array filled from the prompt () and then written to the screen.
After which I will use another set of prompts to get the prices for each of the fruits and place that in the second dimension of the array. Last but not least I will write the whole thing out using document.write().


Can you advise?

insight always appreciated

Thank You
Kevin:confused:

A1ien51
01-23-2003, 03:06 AM
new array() should be new Array()