请问有需要改的地方吗
来源:4-9 编程练习
Tiny丶
2019-06-19 02:44:08
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Math.random()</title>
</head>
<body>
<script>
var num = Math.floor(Math.random()*(9-1+1)+2);
while(input != num) {
var input = prompt("请输入你猜的数字");
if (input > num) {
alert("输入的数字大了");
} else if (input == num) {
alert("恭喜你猜对了");
} else if (input < num) {
alert("输入的数字小了");
}
}
</script>
</body>
</html>
1回答
你好,循环中的判断没有问题,但是要求获取1-9之间的随机数,代码中获取的是2-10之间的,可以修改一下:
自己重新测试下,祝学习愉快!
相似问题