Need help with Javascript array

So have an assignment and cannot figure it out. Had to create a variable that allows the user to input a name.

strings.html to get the names of twenty people (prompt 20 times) from the user. Store these names in an array called names. Convert all the names to uppercase. Next output the twenty names along with the length of the strings.

var who1=prompt("what is your name?");
document.write(who1.toUpperCase());
document.write(who1.length);

My issue is everything I can find on the array is using predefined fields. How do you build the array when it needs the user input?

Comments

  • You can push() elements into array. Example:

    var foo = [];
    foo.push('bar');
  • I had this same assignment, and struggled for the solution to this. We have not covered .push in my course and that was the only solution I seemed to find to my problem. The missing piece for me was using a prompt within the array. For example:

    example=new Array();
    example[0]=prompt("Enter an example here");

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories