Logic order of If Else statements

I have no idea how to balance this out. When I figure out orderMyLogic (4), orderMyLogic (6), and orderMyLogic(11) doesn’t work. When I figure out orderMyLogic (6) and orderMyLogic (11), orderMyLogic (4) doesn’t work.

What is your current code? What different things have you tried? What parts are you confused about?

1 Like

So the point to this lesson is to consider the order of logical expressions. Currently, what you are given is:

if val is less than ten, return "less than ten"
else, if val is less than five, "return "less than five"
else return "greater than or equal to ten"

But the hole in that is, with that exact code, if we try orderMyLogic(4), then the first if (is it less than ten?) is true. So it returns, but it doesn’t return what we want. The point of the lesson is to re-order the if statements (don’t need to actually change them, simply move them around) so that we catch values less than five, THEN values less than ten, THEN the rest.

The logic is almost always the most tricky part of any language. But if you think about it logically, exclude the smallest set first, (or the one that might be included in the larger set), then work your way up, it does make sense.