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.
<html>
 <head>
  <script type="text/javascript">
   function checkData() {
    var age = document.my.age.value
    if ( age.length == 0 || (/[^0-9]/).test(age) ) {
      alert("Too young")
      return false
    }
    return true
   }
  </script> 
  
var testArray = new Array(); // array being declared
 
</head>

Open in new window

CurrymunchAsked:
Who is Participating?
 
scrathcyboyConnect With a Mentor Commented:
No homework on EE -- against their policy.  Ask for a point refund.
0
 
BadotzConnect With a Mentor Commented:
A quick search on the internet for "javascript array" should return some examples of how to populate an array.
0
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.