Basic javaScript:Logical Order in If Else Statements

Basic javaScript:Logical Order in If Else Statements
0

#1

Tell us what’s happening:

y am i not able to get the less than 5 in the output.tell me plss

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(7);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0.

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


#2

The order of conditions matter.

You want to swap your if statement with else if statement because any number that’s less than 10 will be returned before checking if it’s less than 5 next.