# freeCodeCamp Challenge Guide: Comparisons with the Logical Or Operator

freeCodeCamp Challenge Guide: Comparisons with the Logical Or Operator
0

#1

The `logical or` operator (`||`) returns `true` if either of the `operands` is `true`. Otherwise, it returns `false`.

The pattern below should look familiar from prior Challenges:

``````if (num > 10) {
return "No";
}
if (num < 5) {
return "No";
}
return "Yes";
``````

will return “Yes” only if `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";
``````

More solutions to using the "Or" operator
#2

Solution:
function testLogicalOr(val) {
// Only change code below this line

if (val > 20 || val < 10) {
return “Outside”;
}

// Only change code above this line
return “Inside”;
}

// Change this value to test
testLogicalOr(15);

#3

Solution:

If we want to find a value between 2( here 10 and 20 inclusive) numbers the && operator is a must or else all conditions used to test values above 20 and below 10 wont satisfy .
But if we use && operator we wont be using the || operator which must be used at least once in this exercise.

Below solution will satisfy all test conditions but there is a mismatch in the design of the problem itself - BETWEEN cannot be used when we are learning OR operator.

Waiting for comments to check if my understanding is correct.

Solution:
function testLogicalOr(val) {
// Only change code below this line

if ((val > 10 || val == 10) && val <= 20 ) {
return “Inside”;
}

// Only change code above this line
return “Outside”;
}

// Change this value to test
testLogicalOr(10);