当有多个数字时,我正在努力研究if / else语句。例如,当一串数字中是否存在0时,找到真或假。有示例[5,0,2]和[1,3,5]。当有多个数字时,我不知道该怎么办。有人可以帮我理解吗?
function testNum(a) {
if (a = [5, 0, 2]);
return true;
else if (a = [1, 3, 5]);
return false;
}
console.log(testNum[5, 0, 2]);
console.log(testNum[1, 3, 5]);
return a;
result: Error: Unexpected token else
function testNum(a) {
if (a > [5, 0, 2]) {
return "true";
} else {
return "false";
}
}
console.log(testNum([5, 0, 2]);
console.log(testNum([1, 3, 5]);
return a;
result: Error: Unexpected token else
function testNum(a) {
if (a = [5, 0, 2]);
return true;
}
console.log(testNum[5, 0, 2]);
console.log(testNum[1, 3, 5]);
return a;
result: a is not defined
I expect to return a true and a false.