3.5 KiB
3.5 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244d9 | Comparisons with the Logical Or Operator | 1 | 与逻辑或运算符的比较 |
Description
||
)返回true
,如果任一操作数为true
。否则,它返回false
。 逻辑或运算符由两个管道符号( |
)组成。这通常可以在Backspace和Enter键之间找到。以下模式应该从以前的方法点看起来很熟悉: if(num> 10){仅当
返回“否”;
}
if(num <5){
返回“否”;
}
返回“是”;
num
介于5
和10
之间(包括5和10)时,才会返回“Yes”。相同的逻辑可以写成: if(num> 10 || num <5){
返回“否”;
}
返回“是”;
Instructions
if
语句组合成一个语句,如果val
不在10
和20
之间(包括10
和20
,则返回"Outside"
。否则,返回"Inside"
。 Tests
tests:
- text: 你应该使用<code>||</code>操作员一次
testString: 'assert(code.match(/\|\|/g).length === 1, "You should use the <code>||</code> operator once");'
- text: 你应该只有一个<code>if</code>语句
testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
- text: <code>testLogicalOr(0)</code>应返回“Outside”
testString: 'assert(testLogicalOr(0) === "Outside", "<code>testLogicalOr(0)</code> should return "Outside"");'
- text: <code>testLogicalOr(9)</code>应返回“Outside”
testString: 'assert(testLogicalOr(9) === "Outside", "<code>testLogicalOr(9)</code> should return "Outside"");'
- text: <code>testLogicalOr(10)</code>应返回“Inside”
testString: 'assert(testLogicalOr(10) === "Inside", "<code>testLogicalOr(10)</code> should return "Inside"");'
- text: <code>testLogicalOr(15)</code>应返回“Inside”
testString: 'assert(testLogicalOr(15) === "Inside", "<code>testLogicalOr(15)</code> should return "Inside"");'
- text: <code>testLogicalOr(19)</code>应该返回“Inside”
testString: 'assert(testLogicalOr(19) === "Inside", "<code>testLogicalOr(19)</code> should return "Inside"");'
- text: <code>testLogicalOr(20)</code>应该返回“Inside”
testString: 'assert(testLogicalOr(20) === "Inside", "<code>testLogicalOr(20)</code> should return "Inside"");'
- text: <code>testLogicalOr(21)</code>应该返回“Outside”
testString: 'assert(testLogicalOr(21) === "Outside", "<code>testLogicalOr(21)</code> should return "Outside"");'
- text: <code>testLogicalOr(25)</code>应返回“Outside”
testString: 'assert(testLogicalOr(25) === "Outside", "<code>testLogicalOr(25)</code> should return "Outside"");'
Challenge Seed
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
// solution required