其他分享
首页 > 其他分享> > 3.6 switch练习

3.6 switch练习

作者:互联网

练习一:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>switch练习1</title>
		<script type="text/javascript">
			/*
			 * 对于成绩大于60分的,输出'合格'。低于60分的,输出'不合格'
			 * 
			 * 6x  /  10 = 6
			 * 7x  /  10 = 7
			 * 8x  /  10 = 8
			 * 9x  /  10 = 9
			 * 100 /  10 = 10
			 * 
			 */
			var score = 75;
			
			/*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>
	<body>
	</body>
</html>

练习二:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>switch练习2</title>
		<script type="text/javascript">
			/*
			 * 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
			 */
			
			var day=+prompt("请输入一个整数");
			
			
			
				switch(day){
					case 1:
						alert("星期一");
						break;
					case 2:
						alert("星期二");
						break;
					case 3:
						alert("星期三");
						break;
					case 4:
						alert("星期四");
						break;
					case 5:
						alert("星期五");
						break;
					case 6:
						alert("星期六");
						break;
					case 7:
						alert("星期日");
						break;
					default:
						alert("非法参数");
				}
		</script>
	<body>
	</body>
</html>

 

标签:case,break,console,10,练习,alert,3.6,switch
来源: https://www.cnblogs.com/sherryyuan/p/16484866.html