我刚刚了解了 JavaScript,这是我的脚本:
var now = new Date();
var date = now.getDate();
var month = now.getMonth();
var Holidays = [
[8, 3],
[9, 8],
[10, 16],
[11, 7],
[11, 24],
[11, 25],
[11, 26],
[11, 27],
[11, 28],
[11, 29],
[11, 30],
[11, 31],
[0, 1],
[0, 2],
[0, 3],
[0, 4],
[0, 31],
[1, 15],
[1, 18],
[2, 11],
[2, 12],
[2, 13],
[2, 14],
[2, 15],
[2, 29],
[3, 1],
[4, 20],
[5, 26],
[5, 27],
[5, 28]
];
var i = 0;
while (i <= Holidays.length) {
if (check() === true) {
console.log("No school today.");
i = 32;
} else if (check() === false) {
if (i < Holidays.length) {
i++;
} else {
console.log("we work today.");
i++;
}
}
}
function check() {
if (month == Holidays[i][0] && date == Holidays[i][1]) {
return true;
} else {
return false;
}
}
目的是让它在假期数组中打印出“今天没有学校”,否则,它会打印出“我们今天上班”。每当我运行脚本时,它总是说
类型错误 Holidays[i] 未定义
有人可以帮我弄这个吗?