* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2.3 KiB
2.3 KiB
id, title, challengeType, videoUrl, forumTopicId, dashedName
id | title | challengeType | videoUrl | forumTopicId | dashedName |
---|---|---|---|---|---|
56533eb9ac21ba0edf2244d9 | 逻辑或运算符 | 1 | https://scrimba.com/c/cEPrGTN | 16800 | comparisons-with-the-logical-or-operator |
--description--
只要逻辑或运算符||
两边任何一个为true
,那么它就返回true
;否则返回false
。
逻辑或运算符由两个管道符号(|)组成。这个按键位于退格键和回车键之间。
下面这样的语句你应该很熟悉:
if (num > 10) {
return "No";
}
if (num < 5) {
return "No";
}
return "Yes";
只有当num
大于等于 5 或小于等于 10 时,函数返回"Yes"。相同的逻辑可以简写成:
if (num > 10 || num < 5) {
return "No";
}
return "Yes";
--instructions--
请使用逻辑或运算符把两个 if 语句合并为一个 if 语句,如果val
不在 10 和 20 之间(包括 10 和 20),返回"Outside"
。反之,返回"Inside"
。
--hints--
你应该使用一次||
操作符。
assert(code.match(/\|\|/g).length === 1);
你应该只有一个if
表达式。
assert(code.match(/if/g).length === 1);
testLogicalOr(0)
应该返回 "Outside"。
assert(testLogicalOr(0) === 'Outside');
testLogicalOr(9)
应该返回 "Outside"。
assert(testLogicalOr(9) === 'Outside');
testLogicalOr(10)
应该返回 "Inside"。
assert(testLogicalOr(10) === 'Inside');
testLogicalOr(15)
应该返回 "Inside"。
assert(testLogicalOr(15) === 'Inside');
testLogicalOr(19)
应该返回 "Inside"。
assert(testLogicalOr(19) === 'Inside');
testLogicalOr(20)
应该返回 "Inside"。
assert(testLogicalOr(20) === 'Inside');
testLogicalOr(21)
应该返回 "Outside"。
assert(testLogicalOr(21) === 'Outside');
testLogicalOr(25)
应该返回 "Outside"。
assert(testLogicalOr(25) === 'Outside');
--seed--
--seed-contents--
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";
}
testLogicalOr(15);
--solutions--
function testLogicalOr(val) {
if (val < 10 || val > 20) {
return "Outside";
}
return "Inside";
}