# Logical Order in If Else Statement

**URL:** <https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741>\
**Category:** General\
**Created:** [December 1, 2017, 9:20am UTC](https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741 "2017-12-01T09:20:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvin](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@calvin](https://forum.freecodecamp.org/u/calvin)\
**Post date:** [December 1, 2017, 9:20am UTC](https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741/1 "2017-12-01T09:20:40Z")

</div>

**Tell us what’s happening:**

**I have a problem with this**

**Your code so far**

```auto
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(4);

```

**Your browser information:**

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36`.

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

---

<div class="post-metadata">

**Author:** ![michal9909](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/michal9909/32/65875_2.png) [@michal9909](https://forum.freecodecamp.org/u/michal9909)\
**Post date:** [December 1, 2017, 9:26am UTC](https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741/2 "2017-12-01T09:26:52Z")

</div>

If the value is less than 10 then it will return ‘Less than 10’, this includes values like 1, 2, 3 and 4 so you need to make sure that you are checking whether the value is ‘Less than 5’ before you check whether the value is ‘Less than 10’. You need to understand that once the first condition is true and the value is returned other conditions will not be checked.

---

<div class="post-metadata">

**Author:** ![calvin](https://avatars.discourse-cdn.com/v4/letter/c/f475e1/32.png) [@calvin](https://forum.freecodecamp.org/u/calvin)\
**Post date:** [December 1, 2017, 9:31am UTC](https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741/3 "2017-12-01T09:31:51Z")

</div>

Can you send me a screenshot of it?

---

<div class="post-metadata">

**Author:** ![michal9909](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/michal9909/32/65875_2.png) [@michal9909](https://forum.freecodecamp.org/u/michal9909)\
**Post date:** [December 1, 2017, 12:25pm UTC](https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741/4 "2017-12-01T12:25:02Z")

</div>

```auto

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);

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:33pm UTC](https://forum.freecodecamp.org/t/logical-order-in-if-else-statement/161741/5 "2021-01-17T20:33:16Z")

</div>

Closed on January 17, 2021, 8:33pm UTC


