Logical Order in If Else Statements Logic

Tell us what’s happening:
How can I get this
orderMyLogic(6) should return “Less than 10”

Your code so far

function orderMyLogic(val) {
  if (val < 5) {
    return "Less than 5";
  } else if (val < 10) {
    return "Less than  10";
  } else {
    return "Greater than or equal to 10";
  }
}


// Change this value to test
orderMyLogic(5);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; rv:59.0) Gecko/20100101 Firefox/59.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/logical-order-in-if-else-statements

And you get what result?

I think that you might have an extra space in your string. Remember that the output must match exactly what is expected.

function orderMyLogic(val) {
  if (val < 10) {
    return "Less than 10";
  } else if (val < 5) {
    return "Less than 5";
  } else {
    return "Greater than or equal to 10";

  }
}

question says: orderMyLogic(4) should return “Less than 5”

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums


4 is less than 10. So what happens?

is not going through. i felt am missing something

4 is less than 10, so (val < 10) is true and your function returns "Less than 10" instead of "Less than 5".

The order is not right here. It was in your original post. Like @ArielLeslie said a 4 would immediately come out as ‘true’ so the loop ends there.

Thank you all for the input. I got it now.

2 Likes

Pruebe con esto:
function orderMyLogic(val) {
if (val < 10 && val > 5) {
return “Less than 10”;
} else if (val < 5) {
return “Less than 5”;
} else {
return “Greater than or equal to 10”;
}
}
// Change this value to test
orderMyLogic(4);

here’s my solution to the problem

function orderMyLogic(val) {
if (val < 6) {
return “Less than 5”;
} else if (val < 7) {
return “Less than 10”;
} else {
return “Greater than or equal to 10”;
}
}

// Change this value to test
orderMyLogic(7);

1 Like

I’ve also got its now i need to change the value that need to be checked which was 4 and work from top top to bottom vice versa.(I don’t know if i explain that correct but that is how i understand it)