【JS】3.17课后练习
练习一:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>d24c04429 欧永鸿</title>
</head>
<body>
<script>
var time = prompt("请输入时间数字(0-24:");
switch(time) {
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
alert("深夜好");
break;
case "8":
case "9":
case "10":
case "11":
case "12":
alert("上午好");
break;
case "13":
case "14":
case "15":
case "16":
case "17":
case "18":
alert("下午好");
break;
case "19":
case "20":
case "21":
case "22":
case "23":
case "24":
alert("晚上好");
break;
default:
alert("请输入正确的时间数字");
}
</script>
</body>
</html>
练习二:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>d24c04429 欧永鸿</title>
</head>
<body>
<script>
var num1 = prompt("请输入第一个数字");
var num2 = prompt("请输入第二个数字");
var status = num1 > num2 ? num1 : num2;
alert(status);
</script>
</body>
</html>
练习三:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>d24c04429 欧永鸿</title>
</head>
<body>
<script>
var num = prompt("请输入一个数字");
var status = num % 2 == 0 ? "偶数" : "奇数";
alert(num + "是" + status);
</script>
</body>
</html>
练习四:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>d24c04429 欧永鸿</title>
</head>
<body>
<script>
var score = prompt("请输入你的分数");
switch (true) {
case score >= 90:
alert("A");
break;
case score >= 80:
alert("B");
break;
case score >= 70:
alert("C");
break;
case score >= 60:
alert("D");
break;
default:
alert("E");
}
</script>
</body>
</html>