请问老师,这样写正确吗?
来源:4-9 编程练习
慕前端2064318
2019-03-18 12:17:35
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Math.random()</title>
</head>
<body>
<script>
//补充代码
var input = parseInt(prompt("请输入您猜的数字")),
nmb = 9,
i = 0,
x = Math.floor(nmb * Math.random() + 1);
while (input != x) {
if (input > x) {
alert("输入的数字大了")
var input = parseInt(prompt("请输入您猜的数字"));
}
else if (input < x) {
alert("输入的数字小了")
var input = parseInt(prompt("请输入您猜的数字"));
}
}
alert("恭喜您猜对了")
document.write(x)
</script>
</body>
</html>
1回答
你好同学 ,效果实现正确 , 继续加油 ,祝学习愉快 !
相似问题