3.2 KiB
3.2 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
56533eb9ac21ba0edf2244d8 | Comparisons with the Logical And Operator | 1 | 与逻辑和运算符的比较 |
Description
true
时, 逻辑和运算符( &&
)才返回true。如果将if语句嵌套在另一个语句中,则可以实现相同的效果: if(num> 5){如果
if(num <10){
返回“是”;
}
}
返回“否”;
num
大于5
且小于10
则仅返回“Yes”。相同的逻辑可以写成: if(num> 5 && num <10){
返回“是”;
}
返回“否”;
Instructions
val
小于或等于50
且大于或等于25
,则返回"Yes"
。否则,将返回"No"
。 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>testLogicalAnd(0)</code>应返回“否”
testString: 'assert(testLogicalAnd(0) === "No", "<code>testLogicalAnd(0)</code> should return "No"");'
- text: <code>testLogicalAnd(24)</code>应返回“否”
testString: 'assert(testLogicalAnd(24) === "No", "<code>testLogicalAnd(24)</code> should return "No"");'
- text: <code>testLogicalAnd(25)</code>应返回“是”
testString: 'assert(testLogicalAnd(25) === "Yes", "<code>testLogicalAnd(25)</code> should return "Yes"");'
- text: <code>testLogicalAnd(30)</code>应该返回“是”
testString: 'assert(testLogicalAnd(30) === "Yes", "<code>testLogicalAnd(30)</code> should return "Yes"");'
- text: <code>testLogicalAnd(50)</code>应该返回“是”
testString: 'assert(testLogicalAnd(50) === "Yes", "<code>testLogicalAnd(50)</code> should return "Yes"");'
- text: <code>testLogicalAnd(51)</code>应返回“否”
testString: 'assert(testLogicalAnd(51) === "No", "<code>testLogicalAnd(51)</code> should return "No"");'
- text: <code>testLogicalAnd(75)</code>应返回“否”
testString: 'assert(testLogicalAnd(75) === "No", "<code>testLogicalAnd(75)</code> should return "No"");'
- text: <code>testLogicalAnd(80)</code>应返回“否”
testString: 'assert(testLogicalAnd(80) === "No", "<code>testLogicalAnd(80)</code> should return "No"");'
Challenge Seed
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
// solution required