# Stumped on "Comparisons with the Logical Or Operator"

Tell us what’s happening: I understand that any inclusive number should be correct. I also understand the basic syntax based on the example. However, it doesn’t pass the tests. I also tried > 10 and < 20, and got the same errors below. Thanks in advance!
I am missing these 4 points:
testLogicalOr(10) should return "Inside"
testLogicalOr(15) should return "Inside"
testLogicalOr(19) should return "Inside"
testLogicalOr(20) should return “Inside”

Your code so far

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

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

// Only change code above this line
return "Inside";
}

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

Your browser information:

Your Browser User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:55.0) Gecko/20100101 Firefox/55.0`.

Link to the challenge:

Combine the two if statements into one statement which returns “Outside” if val is not between 10 and 20, inclusive. Otherwise, return “Inside”.

You need to use NOT (!) operator to solve this problem

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

if (!(val > 20 || val < 10)) {
return "Inside";
}

// Only change code above this line
return "Outside";
}

// Change this value to test
testLogicalOr(15);
``````
1 Like

As it is your condition will evaluate to true no matter what value you give it. For example 15:

15 > 10 => true
15 < 20 => true

true || true => true

With 1000:

1000 > 10 => true
1000 < 20 => false

true || false => true

You need to use:

`!(val<10 || val>20)`

as your condition to determine if it is inside.

1 Like

You have two issues:

#1) You should only have one return “Outside”; (get rid of the 2nd one)

#2) Your if statement logic is in correct for returning “Outside”

Let’s work through an example so you can see why. If you call the function as follows:

``````testLogicalOr(15);
``````

In the above val is 15, so you your val < 20 evaluates to true and val > 10 evaluates to true. When using the || operator, it only takes one true for the entire statement to evaluate to true. You could reverse the < and > signs in your code, so you have val < 10 || val > 20. This would give you the correct solution without having to use the ! operator.

2 Likes
``````Is this any closer? I had to keep with the ! operator because I am down to only three requirements which haven't been met:
testLogicalOr(10) should return "Inside"
testLogicalOr(15) should return "Inside"
testLogicalOr(19) should return "Inside"

if ((val > 10 || val < 20)) {
return "Inside";
}

// Only change code above this line
return "Outside";
}
``````
1 Like

@nr-mihaylov Thanks, I am making slow progress!

@michal9909 Thanks! I am making slow progress!

The challenge code comment specifically states only change code above the return “Inside”; Your latest code has return “Outside” at the bottom. Change it back to the original and use what I showed in my last reply.

My apologies. Sometimes it takes a 2nd or third look for me. I finally got it right! Yay! Now, I get to have dinner and chill. Thanks again! @RandellDawson, @nr-mihaylov, @michal9909

Solution :
unction 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);