• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

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 = document.my.age.value
    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

2 Solutions
No homework on EE -- against their policy.  Ask for a point refund.
A quick search on the internet for "javascript array" should return some examples of how to populate an array.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now