我正在 JavaScipt 中编写一些非常基本的代码。我正在查看 If 语句。每当我输入超过 100 的数字(无论是 c 还是 d)时,我都不会收到“您的数字超过 100”的警报。我错过了什么???感觉这是一个简单的解决方案,我只是没有看到它。
var c = prompt("Please enter a number between 1 and 100");
var d = prompt("Please enter a number between 1 and 100");
if (c || d <=100) {
if (c == d) {
alert("Your first number is equal to your second number!")
}else{
alert("Your first number is not equal to your second number!")
}
}else{
alert("Your number is over 100")
};
最佳答案
您可以像这样更准确地阅读 if 语句:
if(c || (d < = 100)){
因为除非您输入 0,否则 c 始终为 true,因此它永远不会说“您的数字超过 100”
如果你想检查其中一个是否超过 100,你可以将其重写为类似的内容:
if(c <= 100 || d <= 100){
关于javascript - If 语句包含在 If 语句中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48970676/