switch...case...语句练习

161 阅读1分钟
对于成绩大于60分的,输出“合格”,低于60分的,输出“不合格”

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			var score = 35;
			//方法一:
			// switch(parseInt(score/10)){
			// 	case 10:
			// 	case 9:
			// 	case 8:
			// 	case 7:
			// 	case 6:
			// 	console.log("合格");
			// 	break;
			// default:
			// 	console.log("不合格");
			// 	break;
			// }
			//方法二:
			switch(true){
				case score >= 60:
				console.log("合格");
				break;
			default:
			    console.log("不合格");
				break;
			}
		</script>
	</head>
	<body>
	</body>
</html>