2018-10-04 14:37:37 +01:00
---
id: 56533eb9ac21ba0edf2244d9
title: Comparisons with the Logical Or Operator
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cEPrGTN'
2019-07-31 11:32:23 -07:00
forumTopicId: 16800
2021-01-13 03:31:00 +01:00
dashedName: comparisons-with-the-logical-or-operator
2018-10-04 14:37:37 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
The < dfn > logical or</ dfn > operator (`||` ) returns `true` if either of the < dfn > operands</ dfn > is `true` . Otherwise, it returns `false` .
The < dfn > logical or</ dfn > operator is composed of two pipe symbols: (`||` ). This can typically be found between your Backspace and Enter keys.
2018-10-04 14:37:37 +01:00
The pattern below should look familiar from prior waypoints:
2019-05-17 06:20:30 -07:00
```js
if (num > 10) {
return "No";
}
if (num < 5 ) {
return "No";
}
return "Yes";
```
2020-11-27 19:02:05 +01:00
will return "Yes" only if `num` is between `5` and `10` (5 and 10 included). The same logic can be written as:
2019-05-17 06:20:30 -07:00
```js
if (num > 10 || num < 5 ) {
return "No";
}
return "Yes";
```
2020-11-27 19:02:05 +01:00
# --instructions--
Combine the two `if` statements into one statement which returns `"Outside"` if `val` is not between `10` and `20` , inclusive. Otherwise, return `"Inside"` .
# --hints--
You should use the `||` operator once
```js
assert(code.match(/\|\|/g).length === 1);
```
You should only have one `if` statement
```js
assert(code.match(/if/g).length === 1);
```
`testLogicalOr(0)` should return "Outside"
```js
assert(testLogicalOr(0) === 'Outside');
```
`testLogicalOr(9)` should return "Outside"
```js
assert(testLogicalOr(9) === 'Outside');
```
`testLogicalOr(10)` should return "Inside"
```js
assert(testLogicalOr(10) === 'Inside');
```
`testLogicalOr(15)` should return "Inside"
```js
assert(testLogicalOr(15) === 'Inside');
```
`testLogicalOr(19)` should return "Inside"
```js
assert(testLogicalOr(19) === 'Inside');
```
`testLogicalOr(20)` should return "Inside"
```js
assert(testLogicalOr(20) === 'Inside');
```
`testLogicalOr(21)` should return "Outside"
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(testLogicalOr(21) === 'Outside');
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
`testLogicalOr(25)` should return "Outside"
```js
assert(testLogicalOr(25) === 'Outside');
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
# --seed--
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-10-04 14:37:37 +01:00
```js
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);
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-10-04 14:37:37 +01:00
```js
function testLogicalOr(val) {
if (val < 10 | | val > 20) {
return "Outside";
}
return "Inside";
}
```