Logical Order in If Else Statementz

Logical Order in If Else Statementz
0

#1

Tell us what’s happening:
I have no idea what I am doing wrong here please help.

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:

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

Link to the challenge:


#2

Hi @20curetonc

You need to think about the order in which the if statements are being executed.

If your super stuck:

orderMyLogic(4) is both less than 10 and less than 5, so because the less than 10 gets evaluated first then ir returns "Less than 10". So to get this right you need to switch val < 10 and val < 5 around, along with their corresponding return statements.