如何比较 else if 语句 jS 中的 2 个变量是否为真?
How do I compare if 2 variables are true in an else if statement jS?
我正在尝试执行以下操作:
if (x) {
// then this
} else if (calcDifference = 7) && (currentCMSI = 7) { // problem line
// then this
} else if {
// then this
}
或者这样:
if (x) {
// then this
} else if (calcDifference = 7 && currentCMSI = 7) { // problem line
// then this
} else if {
// then this
}
但我不断收到错误消息,如果 else if 语句中的 2 个不同变量都为真,则比较的正确语法是什么?
都没有!
=
是赋值运算符
==
用于比较两个变量
所以回答你的问题,第二个建议但是==
if (calcDifference == 7 && currentCMSI == 7)
我正在尝试执行以下操作:
if (x) {
// then this
} else if (calcDifference = 7) && (currentCMSI = 7) { // problem line
// then this
} else if {
// then this
}
或者这样:
if (x) {
// then this
} else if (calcDifference = 7 && currentCMSI = 7) { // problem line
// then this
} else if {
// then this
}
但我不断收到错误消息,如果 else if 语句中的 2 个不同变量都为真,则比较的正确语法是什么?
都没有!
=
是赋值运算符
==
用于比较两个变量
所以回答你的问题,第二个建议但是==
if (calcDifference == 7 && currentCMSI == 7)