Can someone help me this issue?

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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";
}
}

orderMyLogic(11);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Logical Order in If Else Statements

Link to the challenge:

The second if-else statement should be the first.

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


What happens when val = 2?

I’ve try but to get ```
orderMyLogic(4)


should return the string

Less than 5

What does it return now? Can you look at your code and figure out that?

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";

  }

}

orderMyLogic(4);

orderMyLogic(4)


should return the string

Less than 5

Let’s walk through your current code.

If val is 4 then this condition is true.

The function will return “Less than 10”
After that return statement we exit the function.

The problem is, this condition is also true.

Because 4 is less than 5.
But the computer is not going to execute that condition.

The lesson is trying to teach the importance of ordering your conditions.

You need to switch the order of two of the conditions so the logic makes sense.

Hope that helps!

1 Like

Thank you. I solve it.