--- id: 56533eb9ac21ba0edf2244d9 title: Comparisons with the Logical Or Operator challengeType: 1 videoUrl: '' localeTitle: 与逻辑或运算符的比较 --- ## Description
逻辑OR运算符( || )返回true ,如果任一操作数true 。否则,它返回false逻辑或运算符由两个管道符号( | )组成。这通常可以在Backspace和Enter键之间找到。以下模式应该从以前的方法点看起来很熟悉:
if(num> 10){
返回“否”;
}
if(num <5){
返回“否”;
}
返回“是”;
仅当num介于510之间(包括5和10)时,才会返回“Yes”。相同的逻辑可以写成:
if(num> 10 || num <5){
返回“否”;
}
返回“是”;
## Instructions
将两个if语句组合成一个语句,如果val不在1020之间(包括1020 ,则返回"Outside" 。否则,返回"Inside"
## 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: testLogicalOr(0)应返回“Outside” testString: 'assert(testLogicalOr(0) === "Outside", "testLogicalOr(0) should return "Outside"");' - text: testLogicalOr(9)应返回“Outside” testString: 'assert(testLogicalOr(9) === "Outside", "testLogicalOr(9) should return "Outside"");' - text: testLogicalOr(10)应返回“Inside” testString: 'assert(testLogicalOr(10) === "Inside", "testLogicalOr(10) should return "Inside"");' - text: testLogicalOr(15)应返回“Inside” testString: 'assert(testLogicalOr(15) === "Inside", "testLogicalOr(15) should return "Inside"");' - text: testLogicalOr(19)应该返回“Inside” testString: 'assert(testLogicalOr(19) === "Inside", "testLogicalOr(19) should return "Inside"");' - text: testLogicalOr(20)应该返回“Inside” testString: 'assert(testLogicalOr(20) === "Inside", "testLogicalOr(20) should return "Inside"");' - text: testLogicalOr(21)应该返回“Outside” testString: 'assert(testLogicalOr(21) === "Outside", "testLogicalOr(21) should return "Outside"");' - text: testLogicalOr(25)应返回“Outside” testString: 'assert(testLogicalOr(25) === "Outside", "testLogicalOr(25) should return "Outside"");' ```
## Challenge Seed
```js function testLogicalOr(val) { // Only change code below this line if (val) { return "Outside"; } if (val) { return "Outside"; } // Only change code above this line return "Inside"; } // Change this value to test testLogicalOr(15); ```
## Solution
```js // solution required ```