--- id: 56533eb9ac21ba0edf2244d8 title: Comparisons with the Logical And Operator challengeType: 1 videoUrl: '' localeTitle: 与逻辑和运算符的比较 --- ## Description
有时你需要一次测试多个东西。当且仅当其左侧和右侧的操作数true时, 逻辑和运算符( && )才返回true。如果将if语句嵌套在另一个语句中,则可以实现相同的效果:
if(num> 5){
if(num <10){
返回“是”;
}
}
返回“否”;
如果num大于5且小于10则仅返回“Yes”。相同的逻辑可以写成:
if(num> 5 && num <10){
返回“是”;
}
返回“否”;
## Instructions
将两个if语句合并为一个语句,如果val小于或等于50且大于或等于25 ,则返回"Yes" 。否则,将返回"No"
## Tests
```yml tests: - text: 你应该使用一次&&运算符 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"");' ```
## Challenge Seed
```js function testLogicalAnd(val) { // Only change code below this line if (val) { if (val) { return "Yes"; } } // Only change code above this line return "No"; } // Change this value to test testLogicalAnd(10); ```
## Solution
```js // solution required ```