[英]Multiple if-else isn't working
var x = prompt("number between 50 and 100");
if (x.match(/hi/)) {
alert("cool");
} else {
alert("neni cool");
} else if (x==50 || x==100) {
alert("skevele");
} else {
alert("nic");
}
谁能解释为什么如果不起作用呢? 感谢您的回答。
您不能像这样堆叠它们。 }else{
语句仅是if / then / else语句中的最后一种情况,因为只有在其他情况没有时才这样做。
if(condition){
what to do
}else if(condition 2){
what to do if the first condition was not met
}else{
if all else fails
}
else if
在else
之后,你就在else if
else
。 else if
将无法正确评估,因为else
结束了if
语句。 如果您希望这两个语句都起作用,请尝试:
f (x.match(/hi/)) {
alert("cool");
} else {
alert("neni cool");
}
if (x==50 || x==100) {
alert("skevele");
} else {
alert("nic");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.