JS输入月份,显示当月的天数 利用case落空简化代码.

// 输入月份,显示当月的天数
// 要求:利用case落空简化代码 如果是2月 则默认为28天即可
<script>
1 3 5 7 8 10 12 31天
4 6 9 11 30天
2 28天
var month = +prompt("请输入月份");
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
alert("31天");
break;
case 4:
case 6:
case 9:
case 11:
alert("30天");
break;
case 2:
alert("28天");
break;
default:
alert("错误的月份");
break;
}
</script>
posted @ 2019-08-23 19:46  深潜海底z  阅读(1123)  评论(0编辑  收藏  举报