var year, month, day, monthSum = 0; var arr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); function getDate() { year = Number(prompt("请输入年")); month = Number(prompt("请输入你的出生月份")); day = Number(prompt("请输入你的出生日期")); for (var i = 0; i < month - 1; i++) { monthSum = monthSum + arr[i] } if ((year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) && month > 2) { monthSum = monthSum + day + 1 document.write("您的生日在" + year + "年" + "是第" + monthSum + "天"); } else { monthSum = monthSum + day document.write("您的生日在" + year + "年" + "是第" + monthSum + "天"); } } getDate();