How do i declare a global array when working with html / xhtml?

Posted on 2008-11-06
Last Modified: 2013-11-19
Question from the lecture handouts :

"In the body of an HTML page, add JavaScript to prompt someone for their age, and write out in the document the years that they have been alive. (e.g. 1990, 1991, 1992, ..., 2007). The actual writing out of the years should be done by a function included in the head section. "

Just looking how to populate the array in the header section of the html document.

Thanks in advance.


  <script type="text/javascript">

   function checkData() {

    var age =

    if ( age.length == 0 || (/[^0-9]/).test(age) ) {

      alert("Too young")

      return false


    return true




var testArray = new Array(); // array being declared


Open in new window

Question by:Currymunch
    LVL 44

    Accepted Solution

    No homework on EE -- against their policy.  Ask for a point refund.
    LVL 29

    Assisted Solution

    A quick search on the internet for "javascript array" should return some examples of how to populate an array.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now