<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>计算天数</title></head><body> <script> var year=prompt("请输入您的出生年份"), month=prompt(("请输入您的出生月份"), day=prompt(("请输入您的出生日期"), monthnum=parseInt(month), yearnum=parseInt(year), daynum=parseInt(day), sum=0, i; if(yearnum%4==0 && yearnum%100!=0){ function num2(){ for(i=0;i<monthnum;i++){sum+=arguments[i]} return sum; } } else if(yearnum%400==0){ function num2{ for(i=0;i<monthnum;i++){sum+=arguments[i]} return sum; } } else{function num1{ for(i=0;i<monthnum;i++){sum+=arguments[i]} return sum; }} num1(31,28,31,30,31,30,31,31,30,31,30,31); num2(31,29,31,30,31,30,31,31,30,31,30,31); var total=sum-daynum console.log("您的生日在"+yearnum+"年"+"第"+total+"天") </script></body></html>
2 回答
日光弥散
TA贡献4条经验 获得超4个赞
var year = prompt("请输入您的出生年份"),
month = prompt("请输入您的出生月份"),
day = prompt("请输入您的出生日期"),
monthnum = parseInt(month) - 1,
yearnum = parseInt(year),
daynum = parseInt(day),
sum = 0,
i;
function num() {
for (i = 0;i < monthnum;i++) { sum += arguments[i] }
}
if (yearnum % 4 == 0 && yearnum % 100 != 0) {
num(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
}
else if (yearnum % 400 == 0) {
num(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
}
else {
num(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
}
var total = sum + daynum
console.log("您的生日在" + yearnum + "年" + "第" + total + "天")
添加回答
举报
0/150
提交
取消