3.0 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--
Якщо оператор logical або (||
) повертає true
, якщо будь-який з operands є true
. В іншому випадку перетворюється на false
.
Оператор логічний або складається з двох символів труби (||
). Зазвичай його можна знайти на клавіатурі між клавіш Backspace та Enter.
Шаблон нижче повинен бути схожим з етапами вище:
if (num > 10) {
return "No";
}
if (num < 5) {
return "No";
}
return "Yes";
стає Yes
тільки, якщо num
між 5
та 10
(5 та 10 включно). Приклад оператора наведено нижче:
if (num > 10 || num < 5) {
return "No";
}
return "Yes";
--instructions--
Об'єднайте два оператори if
в один оператор який перетворить рядок Outside
, якщо val
не знаходиться в діапазоні від 10
до 20
включно. В іншому випадку значення рядка стане 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";
}