Logical Order If Else Statements

Tell us what’s happening:
I’m not understanding how this one is supposed to work its confusing me…please Help

Your code so far

function bar(val) {
  if (val <= 10) 
    return "Less than 10";
  } 
  function foo(val) {
   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/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/logical-order-in-if-else-statements

Why did you choose to create two new functions?

like i said its not making any sense

Anybody please help…im very stuck!!!

I’m trying to help. I’m trying to understand your thought process as you approach this problem so I can help you.

im not understanding the foo or bar in the examples and what they have to do with this since both options come up as less then 10 .

the only one from resetting the code as im sure you know that isn’t checked off is the top one that says: orderMyLogic(4) should return “less than 5”.

I guess the examples don’t make it easy to figure out, and confuse me more than help me.

The foo() and bar() examples show two different functions that use if and else statements. The point of them is to show how the order that you put if statements in matters. Those two functions check the same conditions, but do so in a different order and therefore return different results. You are supposed to add if and else statements to the function orderMyLogic() in the correct order to return the required values.

am i close?
‘’’
function orderMyLogic(val) {
if (val < 10) {
return “Less than 10”;
} if (val < 5) {
return “Less than 5”;
} else {
return “Greater than or equal to 10”;
}
}

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

You’re close, but remember that the order that you put your if statements in matters (this was the point of the foo and bar examples). What would happen if val was equal to 2?

me and java dont mix apparently haha
finally says:

Greater than or equal to 10

orderMyLogic(4) should return “Less than 5” (this one is still wrong)
orderMyLogic(6) should return “Less than 10”
orderMyLogic(11) should return “Greater than or equal to 10”


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

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

Java is a different language. This is JavaScript.

What is the sequence of events when val is 4? Step through your function. What actually happens line-by-line?

4 is less than both of them but then it doesnt come out greater than or equal to 10

i am just changing the if else statements and the orderMyLogic # at the bottom right?

What is happening inside your function, line-by-line?

im not sure im seeing what you are?..
function orderMyLogic(val) {
if (val < 10) {
return “Less than 10”;
} if (val < 5) {
return “Less than 5”;
} else {
return “Greater than or equal to 10”;
}
}

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

The lines of your function happen in order. What is the sequence of events inside your function when the value of val is less than 5?

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

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

now just the first goal is checked and the other two are wrong

You’re just pasting your code over and over. I’m asking you to explain what your code does.

the previous one i just posted says its greater than or equal to 10 in the black box under ask for help on the forum

i guess im not understanding what you mean

Make sure your syntax is correct. After the first iteration of the if statement the next should be “else if” not just “if”