A Month Array to Try



How did I do it? With This...

var aujourd=new Date();

function initArray(){
this.length=12
this[0]="January"
this[1]="February"
this[3]="March"
this[4]="May"
this[5]="June"
this[6]="July"
this[7]="August"
this[8]="Sepetmber"
this[9]="October"
this[10]="November"
this[11]="December"
}

var month=new initArray();
var mon=month[aujourd.getMonth()]

...in a javaScript tag inside the <HEAD></HEAD> tags.
And this...

document.write("Today's date is "+mon+" "+aujourd.getDate()+", 19"+aujourd.getYear()+".<BR>")

...inside the <BODY></BODY> tags.

function tells the computer that when I say "initArray()" I want it to execute the following script.
this.length tells the length of the array. Each item in an array has a number, in this case from 0 to 11 since I have twelve different possible items.
What an array does is take a number and test it up against all of its listed numbers to find a match. When it does, it returns the contents of the match. I've written

var month=new initArray();
var mon=month[aujourd.getMonth()]

This tells the computer to set the word month to a new array. Then, test the value of aujourd.getMonth() against the array, and put that into the variable mon. So if the month is 0, then the array finds its "0" item, and returns the text, "January." If the month is 5, the array finds item 5 and returns "June." That's all there is to it. You can get a similar effect by lining up a million if/then statements, but this is much more effeicient.

1st Page | 2nd Page | 3rd Page | Arrays | Properties

Home | JavaScript | 3D | Old Site | Roommate | The Game | Downloads | 40th Drink | egaP | Humor | Programming | Action Research | Links | Rivard.org