Logical Order in If Else Statementssss

Tell us what’s happening:

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/logical-order-in-if-else-statements

Suppose the value is 4:

if (val < 10) {
    return "Less than 10";
  }

After this if statement the function will return “Less than 10” and jump out of the function as well.

Which means that this code:

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

was never used even once in the function.

Try taking lower value first and then use the greater value later on in the else statement.
Also make use of “console.log()” to check what the function is doing in each if- else statements.

Thanks Dear ): for response