如果指定的年数可以被4整除,那么leapYear()函数将返回“true”,否则返回”false“:
function leapYear(year) {
if (year % 4 == 0) // basic rule
return true; // is leap year
/* else */ // else not needed when statement is "return"
return false; // is not leap year
}
getMonthName()函数返回指定月份的名字:
function getMonthName(month) {
// create array to hold name of each month
var ar = new Array(12);
ar[0] = "January";
ar = "February";
ar = "March";
ar = "April";
ar = "May";
ar = "June";
ar = "July";
ar = "August";
ar = "September";
ar = "October";
ar = "November";
ar = "December";
// return name of specified month (parameter)
return ar[month];
}