Logical Order in If Else Statement

Logical Order in If Else Statement
0

#1

Tell us what’s happening:

I have a problem with this

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:

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

Link to the challenge:


#2

If the value is less than 10 then it will return ‘Less than 10’, this includes values like 1, 2, 3 and 4 so you need to make sure that you are checking whether the value is ‘Less than 5’ before you check whether the value is ‘Less than 10’. You need to understand that once the first condition is true and the value is returned other conditions will not be checked.


#3

Can you send me a screenshot of it?


#4

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

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