Need Help with If Else Statement

Need Help with If Else Statement
0

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

}


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

I’ve run my above code and it kept coming back as "orderMyLogic(11) should return “Greater than or equal to 10"” However; I tried multiple combos of the code many times only to reset the code because nothing was working. I returned the same code above and then it worked.

What I am not understanding is why the code still ran the final else statement if 7 is less than 10?


Logical Order in If Else Statements
#2

Hello, I made some edits to your post as a moderator. You originally posted your question in a thread that had been inactive for several months. I moved your question to a new topic so you can get help better.

I’ve also edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

I am not sure what your problem is. I ran your code and it gave me less than 10. If you are having trouble with a specific freeCodeCamp challenge, could you link to it? Thanks!


#4

your ccode seems good. i don’t see problem here.


#5

I think what you’re missing is that even though you only have orderMyLogic(7); as a call to the function in your own code, the FCC testing harness is calling it with a bunch of different values also, including orderMyLogic(11). That test was apparently failing and is now passing.