<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
/*
60以下:差;
60:及格;
70:一般;
80:良好;
90:优秀;
switch(变量){
case 值1:
代码
break;
case 值2:
代码
break;
default:
其他情况
}
swithch:只能用于等值条件
多重if:可以用于区间
break:跳出switch
*/
var score = prompt("请输入成绩:");
console.log(typeof(score)); //string
switch (score * 1) {
//==>score==90 || score==80
case 90:
case 80:
console.log("优秀");
break;
case 70:
console.log("一般");
break;
case 60:
console.log("及格");
break;
default:
console.log("差");
}
</script>
</body>
</html>
javascript-switch的用法及练习题
最新推荐文章于 2024-03-05 12:42:43 发布