true
,逻辑与 运算符(&&
)才会返回true
。
同样的效果可以通过 if 语句的嵌套来实现:
```js
if (num > 5) {
if (num < 10) {
return "Yes";
}
}
return "No";
```
只有当num
的值在 6 和 9 之间(包括 6 和 9)才会返回 "Yes"。相同的逻辑可被写为:
```js
if (num > 5 && num < 10) {
return "Yes";
}
return "No";
```
val
小于或等于50
并且大于或等于25
,返回"Yes"
。否则,将返回"No"
。
&&
运算符一次。
testString: assert(code.match(/&&/g).length === 1,);
- text: 你应该只有一个if
表达式。
testString: assert(code.match(/if/g).length === 1);
- text: testLogicalAnd(0)
应该返回 "No"。
testString: assert(testLogicalAnd(0) === "No");
- text: testLogicalAnd(24)
应该返回 "No"。
testString: assert(testLogicalAnd(24) === "No");
- text: testLogicalAnd(25)
应该返回 "Yes"。
testString: assert(testLogicalAnd(25) === "Yes");
- text: testLogicalAnd(30)
应该返回 "Yes"。
testString: assert(testLogicalAnd(30) === "Yes");
- text: testLogicalAnd(50)
应该返回 "Yes"。
testString: assert(testLogicalAnd(50) === "Yes");
- text: testLogicalAnd(51)
应该返回 "No"。
testString: assert(testLogicalAnd(51) === "No");
- text: testLogicalAnd(75)
应该返回 "No"。
testString: assert(testLogicalAnd(75) === "No");
- text: testLogicalAnd(80)
应该返回 "No"。
testString: assert(testLogicalAnd(80) === "No");
```