<head>
<meta charset="UTF-8">
<title>星期的判断</title>
</head>
<meta charset="UTF-8">
<title>星期的判断</title>
</head>
<body>
<script>
var dayOfWeek = 4;
<script>
var dayOfWeek = 4;
//if 语句的条件表达式只能为布尔型(可能存在数据类型自动转换)
//switch语句的表达式为任意数据类型(布尔型除外)
// if语句每次执行时都将对变量进行取值操作;而switch只进行一次取值
//wsitch语句进行的是全等运算
if (dayOfWeek == 0) {
document.write('星期天')
} else
if (dayOfWeek == 1) {
document.write('星期一')
} else if (dayOfWeek == 2) {
document.write('星期二')
} else
if (dayOfWeek == 3) {
document.write('星期三')
} else
if (dayOfWeek == 4) {
document.write('星期四')
} else
if (dayOfWeek == 5) {
document.write('星期五')
} else
if (dayOfWeek == 6) {
document.write('星期六')
};
if (dayOfWeek == 0) {
document.write('星期天')
} else
if (dayOfWeek == 1) {
document.write('星期一')
} else if (dayOfWeek == 2) {
document.write('星期二')
} else
if (dayOfWeek == 3) {
document.write('星期三')
} else
if (dayOfWeek == 4) {
document.write('星期四')
} else
if (dayOfWeek == 5) {
document.write('星期五')
} else
if (dayOfWeek == 6) {
document.write('星期六')
};
switch (dayOfWeek) {
case 0:
document.write('星期天')
break;
case 0:
document.write('星期天')
break;
case 1:
document.write('星期一')
break;
case 2:
document.write('星期二')
break;
case 3:
document.write('星期三')
break;
case 4:
document.write('星期四')
break;
case 5:
document.write('星期五')
break;
case 6:
document.write('星期六')
break;
document.write('星期一')
break;
case 2:
document.write('星期二')
break;
case 3:
document.write('星期三')
break;
case 4:
document.write('星期四')
break;
case 5:
document.write('星期五')
break;
case 6:
document.write('星期六')
break;
}
</script>
</body>
</body>
</html>