typeerror - type error undefined in javascript -
i learned javascript , here script:
var = 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 = 0; while (i <= holidays.length) { if (check() === true) { console.log("no school today."); = 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; } }
the purpose make print out "no school today" days in holiday array, otherwise, it'd print out "we work today". whenever run script says
type error holidays[i] undefined
can me this?
at least 1 problem in code
while (i <= holidays.length) {
the last should holidays.length-1, use:
while (i < holidays.length) {
Comments
Post a Comment