用的是switch语句
要求:用弹窗来输入和输出计算天数
特别注意的是2月的天数要看是否为闰年用了个if else
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script>
var year=Number(prompt("请输入年份:"));
var month=Number(prompt("请输入月份:"));
var day;
switch(month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day=31;
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
day=29;
}
else{
day=28;
}
break;
case 4:
case 6:
case 9:
case 11:
day=30;
break;
default:
alert("请输入1-12的数字")
break;
}
alert(year+"年"+month+"月"+"有"+day+"天");
</script>
</head>
<body>
</body>
</html>