Logical Order in If Else help me

Tell us what’s happening:

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0.

If valve < 5 return
Else if val<10 return…

By putting 10 first you’re also returning values less than 5

Hope that helps.

1 Like

Sorry I still don’t understand how to fix it

If you check val < 10 FIRST, the val < 5 block never happens. If you’re doing a series of “less than” comparisons, arrange them least to greatest.

I rearranged the val 10 for 5 and then changed the operator from < to > and I still am not able to make it work

Yup. Now you’re saying “if the value is greater than five, do this.” So suppose you have 12 - following your order, is 12 > 5? Yup. So that block of code runs and exits the if statement. - so the val > 10 clause never gets touched. The < or > was never the issue. It was the order of the values.

I understand but I cannot pass it. I changed the values from 10 to 5 I looked at the code on the hint and I still am stuck

Go back to the code at the top of this thread. Just switch the 10 and 5.

That didnt work. I reset the code and switched the values of the 10 and the 5 and it still wont run

I had to also change the string from 10 to 5 as well