老师您好,check pls,thanks lot
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Math.random()</title>
</head>
<body>
<script>
var a =parseInt(Math.floor(Math.random()*9+1));
while(input != a){
if (input < a) {
alert("小了");
}else if(input > a){
alert("大了");
}
var input = prompt("请输入数字");
}
alert("nice");
</script>
</body>
</html>
正在回答
应该先输入再判断大小
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Math.random()</title>
</head>
<body>
<script>
//补充代码
var random = Math.floor(Math.random()*10+1);
var input;
while (input != random) {
input = Number(prompt("请输入你猜的数字"));
if (input < random) {
alert("输入的数字小了");
} else if (input > random) {
alert("输入的数字大了");
} else {
alert("恭喜你猜对了");
}
}
</script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星