Basic JavaScript - Logical Order in If Else Statements

Tell us what’s happening: It says that 4 should return less than 5, I have the last checks. I can’t seem to find my issue.

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

console.log(orderMyLogic(7, 4, 6, 11));

Your browser information:

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

Challenge Information:

Basic JavaScript - Logical Order in If Else Statements

Hi, read this line very carefully from the lesson and try to understand the example given “The function is executed from top to bottom so you will want to be careful of what statement comes first.”

You are doing the mistake of what lesson is warning you about.

1 Like

You don’t appear to have modified the starting code for this challenge.

If val is 4 then it will trigger the first conditional statement and return “Less than 10”.

This is not what should be returned, so you’ll need to heed the challenge instructions:

The function is executed from top to bottom so you will want to be careful of what statement comes first.

Have you tried considering the order of the conditional statements and why it matters?

1 Like

oh okay I got it, thank you.