- Take a look at this blog post, maybe you will understand. < font size = "3" > recommended tools HBuilder < / font > < / a > < / li >
0 Answer
the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > you can use the following code implementation:
html>
<html>
<head>
<title>星期几查询title>
<meta charset="utf-8" />
head>
<body>
<script>
// 通过 prompt 获取用户输入的数字
var num = prompt("请输入数字(1-7):");
// 根据用户输入的数字返回对应的星期几
var day;
switch (num) {
case "1":
day = "星期一";
break;
case "2":
day = "星期二";
break;
case "3":
day = "星期三";
break;
case "4":
day = "星期四";
break;
case "5":
day = "星期五";
break;
case "6":
day = "星期六";
break;
case "7":
day = "星期日";
break;
default:
day = "输入错误";
}
// 输出结果
alert(day);
// 或者使用 console.log 或 document.write()
script>
body>
html>
After the user enters a number, the corresponding day of the week pops up.
This answer quotes ChatGPT
You can use the following code to return the day of the week based on the number entered by the user:
let dayNum = prompt("请输入数字 1-7,获取对应的星期几:");
let dayName;
switch (dayNum) {
case '1':
dayName = "星期一";
break;
case '2':
dayName = "星期二";
break;
case '3':
dayName = "星期三";
break;
case '4':
dayName = "星期四";
break;
case '5':
dayName = "星期五";
break;
case '6':
dayName = "星期六";
break;
case '7':
dayName = "星期日";
break;
default:
dayName = "输入不合法";
}
console.log(dayName);
In the above code, I use the prompt function to get the number entered by the user, and then use the switch statement to return the day of the week based on the number entered. Finally, use the console.log function to output the result to the console. You can also use the alert or document.write functions to output the results to a browser window.
这家伙很懒,什么都没留下...