Im stuck at using else if statment

Tell us what’s happening:

Your code so far


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

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

Your browser information:

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

Challenge: Logical Order in If Else Statements

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

Hi @levy, welcome to the forum.

Please be aware also of the return statement: look at the test:

orderMyLogic(4) should return “Less than 5”

And at your code:

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

This will return

"Less than 10"

Which is not the desired output.
Hope this helps :+1:

1 Like