dcsimg

Assignment 44: A Possible Answer

This:

<SCRIPT LANGUAGE="JavaScript">

var dayName=new Array(7)
dayName[0]="Sunday"
dayName[1]="Monday"
dayName[2]="Tuesday"
dayName[3]="Wednesday"
dayName[4]="Thursday"
dayName[5]="Friday"
dayName[6]="Saturday"

var MonthName=new Array(12)
MonthName[0]="January"
MonthName[1]="February"
MonthName[2]="March"
MonthName[3]="April"
MonthName[4]="May"
MonthName[5]="June"
MonthName[6]="July"
MonthName[7]="August"
MonthName[8]="September"
MonthName[9]="October"
MonthName[10]="November"
MonthName[11]="December"

var y=new Date();
var Today = y.getDay()
var Mon = y.getMonth()

document.write("Today is "+dayName[Today] + " in the month of " +MonthName[Mon]);

</SCRIPT>

 

 

Gives you this:

     Notice above that a new array was created containing the months. Then, the month was called for from the Date object and given the variable name "Mon". You'll also notice that the month does not require that a number 1 be added. That's because 0 is the first month, whereas Sunday is a day to start the run of days. The month is then called for in the document.write statement.

 

Did You Get It?

 

Back to the Index Page