这样可以吗?
来源:4-9 编程练习
前端SoEasy
2019-05-01 13:50:21
var n =Math.floor(Math.random()*(9-1+1)+1);
while(input!=n){
var input=prompt("请输入1-9你猜的数字");
if (input>n) {
alert("输入的数字大了");
} else if (input<n) {
alert("输入的数字小了");
}
}
if (input=n) {
alert("猜对了");
}
1回答
你好,最后if判断中有问题,判断相等应该是两个等号,一个等号是赋值不是判断哦。
最后这个判断不写也可以,因为while循环外判断的就是相等的情况。

祝学习愉快!
相似问题