Order In if statements

Tell us what’s happening:

guys I dont get the purpose of this challenge , where it say change order so that it will return the correct statements in all cases. what does it mean?

Your code so far


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";
}
}

orderMyLogic(7);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5.

Challenge: Logical Order in If Else Statements

Link to the challenge:

It means arrange the if statement so that the function returns a logical response. Have you made the tests pass? What solution are you submitting?

1 Like

yes, passed it I saw the solution. but I don’t get the meaning this sentence:
change the order of logic in the function Sto that I will return THE CORRECT STATEMENTS IN ALL CASES.

If you want to understand the meaning of that statement, reset the challenge, copy and paste the following :

console.log(orderMyLogic(1));
console.log(orderMyLogic(4));
console.log(orderMyLogic(7));
console.log(orderMyLogic(7));
console.log(orderMyLogic(7));
console.log(orderMyLogic(20));

From the explanation of the challenge, it is expected that if you pass a value less than 5 it should return the text “Less than 5” and if you pass a value greater or equal to 5 but less than 10, you should see the text “Less than 10” otherwise “Greater than or equal to 10”. Look at what is in the console and compare with the output of the correct solution you are submitting.

1 Like

thank u so much. got it :slightly_smiling_face:

1 Like

Hi, @SARA1985.
Another important note on this is to understand that after a return statement the code stops and gives no other output, so the logic is to return outputs for conditions in ascending order based on instruction or need.

1 Like

thank u :slight_smile: