谢谢大家浏览,希望大家能给我多提提意见,有不对的地方大家畅所欲言,一定及时改正
例题一
<script>
/* 根据当前的时间,提示用户要做的事情
5-7点 早上好
7-11点 上午好,祝您心情愉快
11-13点 中午好
13-17点 下午好
17-21点 晚上好
21-23点 夜深了,注意身体哟
其它情况 凌晨了,该休息了 */
let date = Number(prompt("请输入时间:"));
if (date >= 5 && date < 7) {
alert("早上好");
} else if (date >= 7 && date < 11) {
alert("上午好,祝您心情愉快");
} else if (date >= 11 && date < 13) {
alert("中午好");
} else if (date >= 13 && date < 17) {
alert("下午好");
} else if (date >= 17 && date < 21) {
alert("晚上好");
} else if (date >= 21 && date < 23) {
alert("夜深了,注意身体哟");
} else {
alert("凌晨了,该休息了");
}
</script>
例题二
<script>
//比较两个数的最大值 (用户依次输入2个值,最后弹出最大的那个值)
let num1 = Number(prompt("请输入第一个数字:"));
let num2 = Number(prompt("请输入第二个数字:"));
if (num1 > num2) {
alert(num1);
} else {
alert(num2);
}
</script>
例题三
<script>
// 用户输入一个数,来判断是奇数还是偶数
let num = Number(prompt("请输入一个数:"));
if (num % 2 == 0) {
alert("偶数");
} else {
alert("奇数");
}
</script>
例题四
<script>
//根据用户输入的数值(数字1 到 数字 7),返回星期几
let week = Number(prompt("请输入数字:1~7"));
if (week == 1) {
alert("星期一");
} else if (week == 2) {
alert("星期二");
} else if (week == 3) {
alert("星期三");
} else if (week == 4) {
alert("星期四");
} else if (week == 5) {
alert("星期五");
} else if (week == 6) {
alert("星期六");
} else if (week == 7) {
alert("星期日");
} else {
alert("输入有误,请重新输入!");
}
</script>
例题五
<script>
/* 接收班长口袋里的钱数?
若大于等于2000,请大家吃西餐。
若小于2000,大于等于1500,请大家吃快餐。
若小于1500,大于等于1000,请大家喝饮料。
若小于1000,大于等于500,请大家吃棒棒糖。
否则提醒班长下次把钱带够 */
let money = Number(prompt("请输入班长口袋里的钱数:"));
if (money >= 2000) {
alert("大家吃西餐");
} else if (money >= 1500) {
alert("大家吃快餐");
} else if (money >= 1000) {
alert("大家喝饮料");
} else if (money >= 500) {
alert("大家吃棒棒糖");
} else if (money < 0 || money != Number) {
alert("输入有误");
} else {
alert("班长下次把钱带够");
}
</script>