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
2018-10-04 14:37:37 +01:00
---
## Description
< section id = 'description' >
The < dfn > logical or< / dfn > operator (< code > ||< / code > ) returns < code > true< / code > if either of the < dfn > operands< / dfn > is < code > true< / code > . Otherwise, it returns < code > false< / code > .
2019-11-16 21:30:52 -05:00
The < dfn > logical or< / dfn > operator is composed of two pipe symbols: (< code > ||< / code > ). 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";
```
2018-10-04 14:37:37 +01:00
will return "Yes" only if < code > num< / code > is between < code > 5< / code > and < code > 10< / code > (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";
```
2018-10-04 14:37:37 +01:00
< / section >
## Instructions
< section id = 'instructions' >
Combine the two < code > if< / code > statements into one statement which returns < code > "Outside"< / code > if < code > val< / code > is not between < code > 10< / code > and < code > 20< / code > , inclusive. Otherwise, return < code > "Inside"< / code > .
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
- text: You should use the < code > ||</ code > operator once
2019-07-13 00:07:53 -07:00
testString: assert(code.match(/\|\|/g).length === 1);
2018-10-04 14:37:37 +01:00
- text: You should only have one < code > if</ code > statement
2019-07-13 00:07:53 -07:00
testString: assert(code.match(/if/g).length === 1);
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(0)</ code > should return "Outside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(0) === "Outside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(9)</ code > should return "Outside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(9) === "Outside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(10)</ code > should return "Inside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(10) === "Inside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(15)</ code > should return "Inside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(15) === "Inside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(19)</ code > should return "Inside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(19) === "Inside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(20)</ code > should return "Inside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(20) === "Inside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(21)</ code > should return "Outside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(21) === "Outside");
2018-10-04 14:37:37 +01:00
- text: < code > testLogicalOr(25)</ code > should return "Outside"
2019-07-13 00:07:53 -07:00
testString: assert(testLogicalOr(25) === "Outside");
2018-10-04 14:37:37 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```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);
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
function testLogicalOr(val) {
if (val < 10 | | val > 20) {
return "Outside";
}
return "Inside";
}
```
< / section >