JavaScript: If the score is greater than 60 points, output "pass". If the score is less than 60, output "unqualified" (using switch statement)

Question: For those with a score greater than 60 points, output "pass". If the score is less than 60, the output is "unqualified"?
For this problem, we generally use the if statement is relatively simple, the switch statement is more troublesome, but there can be another simpler method in JavaScript: the
following is the code I implemented in two ways: the
first one:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>switch练习1</title>
		<script type="text/javascript">
			/*
			 * 对于成绩大于60分的,输出'合格'。低于60分的,输出'不合格'
			 */
			var score=75;
			switch(parseInt(score/10)){
    
    
				case 10:
				case 9:
				case 8:
				case 7:
				case 6:
					console.log("合格");
				break;
				default:
					console.log("不合格");
					break;
			}
		</script>
	<body>
	</body>
</html>

The second is relatively simple but
note : only available in JavaScript:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>switch练习1</title>
		<script type="text/javascript">
			/*
			 * 对于成绩大于60分的,输出'合格'。低于60分的,输出'不合格'
			 */
			var score=75;
			
			switch(true){
    
    
				case score >=60:
				console.log("合格");
				break;
				default:
					console.log("不合格");
					break;
			}
		</script>
	<body>
	</body>
</html>

Guess you like

Origin blog.csdn.net/weixin_43398418/article/details/112601456