2018-10-04 13:37:37 +00:00
---
id: 56533eb9ac21ba0edf2244d9
title: Comparisons with the Logical Or Operator
challengeType: 1
2019-02-14 17:24:02 +00:00
videoUrl: 'https://scrimba.com/c/cEPrGTN'
2019-07-31 18:32:23 +00:00
forumTopicId: 16800
2021-01-13 02:31:00 +00:00
dashedName: comparisons-with-the-logical-or-operator
2018-10-04 13:37:37 +00:00
---
2020-11-27 18:02:05 +00: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 13:37:37 +00:00
The pattern below should look familiar from prior waypoints:
2019-05-17 13:20:30 +00:00
```js
if (num > 10) {
return "No";
}
if (num < 5 ) {
return "No";
}
return "Yes";
```
2021-03-03 00:12:12 +00: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 13:20:30 +00:00
```js
if (num > 10 || num < 5 ) {
return "No";
}
return "Yes";
```
2020-11-27 18:02:05 +00:00
# --instructions--
2021-03-03 00:12:12 +00:00
Combine the two `if` statements into one statement which returns the string `Outside` if `val` is not between `10` and `20` , inclusive. Otherwise, return the string `Inside` .
2020-11-27 18:02:05 +00:00
# --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);
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(0)` should return the string `Outside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(0) === 'Outside');
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(9)` should return the string `Outside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(9) === 'Outside');
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(10)` should return the string `Inside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(10) === 'Inside');
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(15)` should return the string `Inside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(15) === 'Inside');
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(19)` should return the string `Inside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(19) === 'Inside');
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(20)` should return the string `Inside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(20) === 'Inside');
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(21)` should return the string `Outside`
2018-10-04 13:37:37 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(21) === 'Outside');
2018-10-04 13:37:37 +00:00
```
2021-03-03 00:12:12 +00:00
`testLogicalOr(25)` should return the string `Outside`
2020-11-27 18:02:05 +00:00
```js
assert(testLogicalOr(25) === 'Outside');
```
2018-10-04 13:37:37 +00:00
2020-11-27 18:02:05 +00:00
# --seed--
2018-10-04 13:37:37 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-10-04 13:37:37 +00: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 18:02:05 +00:00
# --solutions--
2018-10-04 13:37:37 +00:00
```js
function testLogicalOr(val) {
if (val < 10 | | val > 20) {
return "Outside";
}
return "Inside";
}
```