Basic JS - Logical "Or" Operator Inclusivity

Hello,

I am wondering about this particular exercise in the Basic JS module of the JS Algorithms and Data Structures certification program. Is it a general “rule” that the numbers themselves are inclusive—regardless of < or > signs—whenever we use a Logical “Or” operator? My intuitive thought would be that they wouldn’t be included. The default lesson code threw me off:


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:


Can anyone shed any light on this? Thanks! Glad to be a part of FCC.

  **Your browser information:**

Challenge: Comparisons with the Logical Or Operator

Link to the challenge:

I’m not sure what you mean since I see no logical OR in the code. I assume you mean something like this:

if (age > 19 || age < 13) {
  console.log('not a teenager');
} else {
  console.log('teenager');
}

In this case, 19 and 13 would both be a “teenager”.

This is functionally no different than writing:

if (age > 19) {
  console.log('not a teenager');
} else if (age < 13) {
  console.log('not a teenager');
} else {
  console.log('teenager');
}
1 Like