Logical Order in If Else Statements Help

Logical Order in If Else Statements Help
0.0 0

#1

Tell us what’s happening:
Hey guys, the camper bot doesn’t really help me here. It’s just giving me two ways it is incorrect, I don’t know which order would be best to prove both of these statements

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

Remember that an else is only evaluated if the preceding if is false. Your first if checks if something is less than 10. Your following else checks if that thing is less than 5. It will never enter that block because 5 is less than 10, so the first if would have evaluated to true and returned "Less than 10".


#4

Hey I just finished the assignment, thanks for the quick reply.