Comparisons with the Logical Or Operator with only one if


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

 if (val < 25 || val > 0) {
  return "Outside";
}

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

testLogicalOr(15);


https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-or-operator

can u tell me how to do this with only one if?

Hi @Rosley ,

Your ‘if’ syntax is perfect.
Look at the condition which you’re checking for. The instruction says, function returns the string Outside if val is not between 10 and 20

Hope it helps

i didnt understand what u just said :sweat_smile:
but thanks for helping! :wink:
atleast

you have some isues here

I have drawn this condition
as with the OR operator the condition is true when one of the true is true, this is true for any number

what do u mean @ilenia :thinking: :face_with_raised_eyebrow:
r u saying like i have to replace something from my code?

@Rosley ,

any positive number will be greater than 0, so your if condition will always be true

its still not working… :sob:

the code has to return ‘Outside’, if the value of variable ‘val’ is not between 10 and 20.
your code has to check for those numbers and not 0 or 25

// running tests
testLogicalOr(10)
should return the string
Inside
testLogicalOr(15) should return the string
Inside
testLogicalOr(19)
should return the string
Inside
testLogicalOr(20)
should return the string
Inside
// tests completed

thats the problem

@Rosley ,

You could test your code by printing it in the console like this:

console.log(testLogicalOr(15));

You will see the output of your code in the console (output will be ‘Outside’)
The code has to print ‘Inside’ if the number you pass to your function is in the range of 10-20. So if 15 is passed you need to see ‘Inside’ on your console.

This is good to know to test your code. But if you are still confused, the part to be changed in your code is

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

so what is the thing which is wrong in it

sorry, just edited it…made a silly mistake with the < …my bad :upside_down_face:

:face_with_raised_eyebrow:
what do you mean about that?

function testLogicalOr(val) {

  // Only change code below this line
// and here you have to change value value is between 10 and 20 
  if (val < 10 || val > 20){

    return "Outside";

  }

  // Only change code above this line

  return "Inside";  // in your code here it is in lowercase 'inside' change it to 'Inside'

}

so that means to the lesser property i have to add ‘<’ and to the greater property i have to add ‘>’

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

thank u all of my code was good but i was just having the mistake on “'I’nside”.!
like seriously!
sorry my bad! :sweat_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.