www.webdeveloper.com
Results 1 to 6 of 6

Thread: Returning name.length and to.UpperCase from a Array

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    7

    Returning name.length and to.UpperCase from a Array

    Needing help with the following script. I am tasked to return the name.length individually for names entered in the prompt as well as change from lower case to upper case. With the current script it returns a list of names in the number of names not the individual length of each name nor can I get document.write(word.toUpperCase(); to work. Script below:


    <html>
    <head>
    </head>
    <body>
    <p>Enter 20 names</p>
    <script>
    names = new Array();
    i = 0;
    do {
    next = window.prompt("Enter the Next Name", "");
    if (next > " ") names[i] = next;
    i = i + 1;
    }
    while (next > " ");
    document.write("<h2>" + (names.length) + " names entered.</h2>");
    document.write("<ol>");
    for (i in names) {
    document.write("<li>" + names[i] + "<br>");
    }
    document.write("</ol>");
    </script>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,351
    See if you can figure out where to put this line.
    Code:
    document.write("<li>" + names[i].toUpperCase() + ' is ' +names[i].length + " characters long<br>");
    BTW:
    1. You should put you code between [ code] and [ /code] tags (without the spaces)
    to highlight your scripts
    2. You should learn a substitute for document.write as it is a deprecated command.

  3. #3
    Join Date
    Dec 2013
    Posts
    7

    NOOB still not figuring it out

    Thank you for the quick response. My new code is as follows but I get [function toUpperCase() { [native code] }is1] now and not name entered but length of name is correct:


    <html>
    <head>
    </head>
    <body>
    <p>Enter 20 names</p>
    <script>
    names = new Array();
    i = 0;
    do {
    next = window.prompt("Enter the Next Name", "");
    if (next > " ") names[i] = next;
    i = i + 1;
    }
    while (next > " ");
    document.write("<ol>");
    for (i in names) {
    document.write("<li>"+names[i].toUpperCase + 'is' + names[i].length);
    }
    document.write("</ol>");
    </script>

    </body>
    </head>

  4. #4
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,351
    You're still missing 2 things: 1 for your program and another for the forum.

    1. You forgot the () after the .toUpperCase call in your code

    2. You forgot to enclose your code between [ code] and [ /code] tags (without the spaces)
    to make it easier for readers to copy, test, debug and return. It will also retain your formatting

    Again, you should look into replacing the document.write with more modern code elements.

  5. #5
    Join Date
    Dec 2013
    Posts
    7

    Code is Working

    Thanks code working great. I will remember <code> </code> next time.

  6. #6
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,351
    Quote Originally Posted by nu360design View Post
    Thanks code working great. I will remember <code> </code> next time.
    Use [ and ]

    Not < and >

    You're most welcome.
    Happy to help
    Good Luck!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles