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