老师,可以帮忙优化一下吗,谢谢
来源:4-9 编程练习
Moomin6
2019-05-27 22:16:55
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Math.random()</title>
</head>
<body>
<script>
//补充代码
var num = prompt("请输入你猜的数字");
var numRandom = Math.ceil(Math.random()*9);
while(num != numRandom){
if(num > numRandom){
alert("恭喜你大了");
num = prompt("请输入你猜的数字");
}else if(num < numRandom){
alert("恭喜你小了");
num = prompt("请输入你猜的数字");
}
}
if(num == numRandom){
alert("恭喜你猜对了");
}
</script>
</body>
</html>
1回答
同学你好!
经过测试,代码效果实现的很好哟~
如果帮助到了你 欢迎采纳 祝学习愉快~
相似问题