JS的流程控制语句之分支语句
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var age = 20 // 成年人观看
if (age > 18){
console.log("成年人观看")
} else {
console.log("未成年人观看")
}
var score = 65 // 及格
if (score > 100 || score < 0) {
console.log("数字应该在0~100之间")
} else if (score > 90) {
console.log("优秀")
} else if (score > 80) {
console.log("良好")
} else if (score > 60){
console.log("及格")
} else{
console.log("不及格")
}
var week = 123 // 非法输入
switch (week){
case 0:console.log("星期日");break
case 1:console.log("星期一");break
case 2:console.log("星期二");break
case 3:console.log("星期三");break
case 4:console.log("星期四");break
case 5:console.log("星期五");break
case 6:console.log("星期六");break
default:console.log("非法输入");
}
</script>
</head>
<body>
<h1>welcome to JS!</h1>
</body>
</html>
![](https://img2022.cnblogs.com/blog/1413093/202206/1413093-20220602205553940-368209146.png)