var count = 0; for (var i = 1; i <= 12; i++) { for (var j = 1; j <= 31; j++) { var day =("0" + j).slice(-2) var dayten = Number( day.charAt(0)); var dayone = Number(day.charAt(1)); if (i == (dayten + dayone)) { count++ } } } //4月31日の分だけ例外なので-1する console.log(count-1);