||
) returns true
if either of the operands is true
. Otherwise, it returns false
.
The logical or operator is composed of two pipe symbols (|
). This can typically be found between your Backspace and Enter keys.
The pattern below should look familiar from prior waypoints:
if (num > 10) {will return "Yes" only if
return "No";
}
if (num < 5) {
return "No";
}
return "Yes";
num
is between 5
and 10
(5 and 10 included). The same logic can be written as:
if (num > 10 || num < 5) {
return "No";
}
return "Yes";
if
statements into one statement which returns "Outside"
if val
is not between 10
and 20
, inclusive. Otherwise, return "Inside"
.
||
operator once
testString: assert(code.match(/\|\|/g).length === 1, 'You should use the ||
operator once');
- text: You should only have one if
statement
testString: assert(code.match(/if/g).length === 1, 'You should only have one if
statement');
- text: testLogicalOr(0)
should return "Outside"
testString: assert(testLogicalOr(0) === "Outside", 'testLogicalOr(0)
should return "Outside"');
- text: testLogicalOr(9)
should return "Outside"
testString: assert(testLogicalOr(9) === "Outside", 'testLogicalOr(9)
should return "Outside"');
- text: testLogicalOr(10)
should return "Inside"
testString: assert(testLogicalOr(10) === "Inside", 'testLogicalOr(10)
should return "Inside"');
- text: testLogicalOr(15)
should return "Inside"
testString: assert(testLogicalOr(15) === "Inside", 'testLogicalOr(15)
should return "Inside"');
- text: testLogicalOr(19)
should return "Inside"
testString: assert(testLogicalOr(19) === "Inside", 'testLogicalOr(19)
should return "Inside"');
- text: testLogicalOr(20)
should return "Inside"
testString: assert(testLogicalOr(20) === "Inside", 'testLogicalOr(20)
should return "Inside"');
- text: testLogicalOr(21)
should return "Outside"
testString: assert(testLogicalOr(21) === "Outside", 'testLogicalOr(21)
should return "Outside"');
- text: testLogicalOr(25)
should return "Outside"
testString: assert(testLogicalOr(25) === "Outside", 'testLogicalOr(25)
should return "Outside"');
```