输入一个年月日判断这是某年的第几天
//判断这是一年的第几天
//通过用if来把所有的条件都判断一遍(用if 并不用else if :else if并不能把所有的条件都过一遍,天数无法累加)
//输入年
//输入月
//输入日
var year = parseInt(prompt('请输入年份'));
var month = parseInt(prompt('请输入月份'));
var day = parseInt(prompt('请输入日期'));
//天数累加
//闰年 2月29 平年2月28 通过平年闰年来判断月有多少天
//1 3 5 7 8 10 12 31 天
//4 6 9 11 30
// 准备一个容器 来累加天数(if 语句)
var date = day;
//根据月份来进行判断 好知道是多少天
//大于1 累加一月的天数(累加 +=)
//大于2 累加一月和二月的天数
//大于3 累加一 二 三月
if (month > 1) {
date += 30;
}
if (month > 2) {
// 闰年的判断语句,如果为真29天 ,如果为假 28天
date += (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) ? 29 : 28;//优先级 非 与 或
}
if (month > 3) {
date += 31;
}
if (month > 4) {
date += 30;
}
if (month > 5) {
date += 31;
}
if (month > 6) {
date += 30;
}
if (month > 7) {
date += 31;
}
if (month > 8) {
date += 31;
}
if (month > 9) {
date += 30;
}
if (month > 10) {
date += 31;
}
if (month > 11) {
date += 30;
}
alert(`第${date}天`)