3.6 KiB
3.6 KiB
id, title, challengeType, videoUrl, forumTopicId, localeTitle
| id | title | challengeType | videoUrl | forumTopicId | localeTitle |
|---|---|---|---|---|---|
| 56533eb9ac21ba0edf2244d9 | Comparisons with the Logical Or Operator | 1 | https://scrimba.com/c/cEPrGTN | 16800 | Сравнение с логическим или оператором |
Description
|| ) возвращает true если любой из операндов true . В противном случае возвращается false . Логический или оператор состоит из двух символов трубы ( | ). Обычно это можно найти между клавишами Backspace и Enter. Нижеприведенный рисунок должен выглядеть знакомым с предыдущих точек: если (num> 10) {вернет «Да» только в том случае, если
вернуть «Нет»;
}
if (num <5) {
вернуть «Нет»;
}
вернуть «Да»;
num находится между 5 и 10 (включено 5 и 10). Та же логика может быть записана как: если (num> 10 || num <5) {
вернуть «Нет»;
}
вернуть «Да»;
Instructions
if в один оператор, который возвращает "Outside" если val не находится между 10 и 20 , включительно. В противном случае верните "Inside" .
Tests
tests:
- text: You should use the <code>||</code> operator once
testString: assert(code.match(/\|\|/g).length === 1);
- text: You should only have one <code>if</code> statement
testString: assert(code.match(/if/g).length === 1);
- text: <code>testLogicalOr(0)</code> should return "Outside"
testString: assert(testLogicalOr(0) === "Outside");
- text: <code>testLogicalOr(9)</code> should return "Outside"
testString: assert(testLogicalOr(9) === "Outside");
- text: <code>testLogicalOr(10)</code> should return "Inside"
testString: assert(testLogicalOr(10) === "Inside");
- text: <code>testLogicalOr(15)</code> should return "Inside"
testString: assert(testLogicalOr(15) === "Inside");
- text: <code>testLogicalOr(19)</code> should return "Inside"
testString: assert(testLogicalOr(19) === "Inside");
- text: <code>testLogicalOr(20)</code> should return "Inside"
testString: assert(testLogicalOr(20) === "Inside");
- text: <code>testLogicalOr(21)</code> should return "Outside"
testString: assert(testLogicalOr(21) === "Outside");
- text: <code>testLogicalOr(25)</code> should return "Outside"
testString: assert(testLogicalOr(25) === "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
function testLogicalOr(val) {
if (val < 10 || val > 20) {
return "Outside";
}
return "Inside";
}