true
时, 逻辑和运算符( &&
)才返回true。如果将if语句嵌套在另一个语句中,则可以实现相同的效果: if(num> 5){如果
if(num <10){
返回“是”;
}
}
返回“否”;
num
大于5
且小于10
则仅返回“Yes”。相同的逻辑可以写成: if(num> 5 && num <10){
返回“是”;
}
返回“否”;
val
小于或等于50
且大于或等于25
,则返回"Yes"
。否则,将返回"No"
。 &&
运算符
testString: 'assert(code.match(/&&/g).length === 1, "You should use the &&
operator once");'
- text: 你应该只有一个if
语句
testString: 'assert(code.match(/if/g).length === 1, "You should only have one if
statement");'
- text: testLogicalAnd(0)
应返回“否”
testString: 'assert(testLogicalAnd(0) === "No", "testLogicalAnd(0)
should return "No"");'
- text: testLogicalAnd(24)
应返回“否”
testString: 'assert(testLogicalAnd(24) === "No", "testLogicalAnd(24)
should return "No"");'
- text: testLogicalAnd(25)
应返回“是”
testString: 'assert(testLogicalAnd(25) === "Yes", "testLogicalAnd(25)
should return "Yes"");'
- text: testLogicalAnd(30)
应该返回“是”
testString: 'assert(testLogicalAnd(30) === "Yes", "testLogicalAnd(30)
should return "Yes"");'
- text: testLogicalAnd(50)
应该返回“是”
testString: 'assert(testLogicalAnd(50) === "Yes", "testLogicalAnd(50)
should return "Yes"");'
- text: testLogicalAnd(51)
应返回“否”
testString: 'assert(testLogicalAnd(51) === "No", "testLogicalAnd(51)
should return "No"");'
- text: testLogicalAnd(75)
应返回“否”
testString: 'assert(testLogicalAnd(75) === "No", "testLogicalAnd(75)
should return "No"");'
- text: testLogicalAnd(80)
应返回“否”
testString: 'assert(testLogicalAnd(80) === "No", "testLogicalAnd(80)
should return "No"");'
```