Please can i get help Logical Order in If Else Statements

Please can i get help Logical Order in If Else Statements
0.0 0

#1

Tell us what’s happening:

Your code so far

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

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

orderMyLogic(7);```
**Your browser information:**

Your Browser User Agent is: ```Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0```.

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

#2

When you call the function with 5, your code will return “Less than 10”, because the first if asks, if 5 < 10. Since 5 is less than 10, the function returns “Less then 10”. You need to rearrange the code, so that it checks for values less than 5 first.

orderMyLogic(5);

#3

okay.
should i call with the function in two different ways on just one.
really really confuse;

orderMyLogic(5);
orderMyLogic(7);

#4

You don’t have to call any functions. The FCC tests which run when you click the Run tests button make the calls for you and validate your function returns the correct value for each call.

If you are still failing tests, please post your code and tell us which tests are still failing.

To enter a code block into the forum, 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.


#5
<p>  
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";
  }
}
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
orderMyLogic(5);
orderMyLogic(7);


requirements
orderMyLogic(4) should return "Less than 5"
orderMyLogic(6) should return "Less than 10"
orderMyLogic(11) should return "Greater than or equal to 10"

  </p>

#6

The problem is you have not changed your function, after I first told you what the problem was. Your code should return “Less than 5” when the number passed into your function (represented by val) is less than 5. Your code should return “Less than 10” if val was not less than 5 AND val is less than 10. Finally, if neither of the above situations are true, then your code should return “Greater than or equal to 10”.

To solve this challenge you need to change the order of either the if statement, the else if statement or the else statement to have your function meet the above requirements.


#7

okay @randelldawson.
Thanks i finally fix it. :slight_smile:
Good to move :raised_hands:


#8

why is this telling me SyntaxError: unterminated regular expression literal


#9

can you show the code


#10

If you are asking a completely new question, please start a new topic instead of putting your question on someone else’s topic. If you are seeking clarification about responses given to the OP, then ask here. Otherwise, please start a new topic under the Help category.

Thank you.