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

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

Who is Participating?
scrathcyboyConnect With a Mentor Commented:
No homework on EE -- against their policy.  Ask for a point refund.
BadotzConnect With a Mentor Commented:
A quick search on the internet for "javascript array" should return some examples of how to populate an array.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.