# Comparisons with the logical And Operator is not working

**URL:** <https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920>\
**Category:** General\
**Created:** [November 19, 2017, 10:30pm UTC](https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920 "2017-11-19T22:30:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![teaglebuilt](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/teaglebuilt/32/161033_2.png) [@teaglebuilt](https://forum.freecodecamp.org/u/teaglebuilt)\
**Post date:** [November 19, 2017, 10:30pm UTC](https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920/1 "2017-11-19T22:30:21Z")

</div>

this is my code:

```auto
function testLogicalAnd(val) {
  // Only change code below this line

  if (val <= 50 && val >= 25) {
      return "Yes";
    } else {
    return "no";
  }
};
  // Only change code above this line
  
return "No";

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

```

-------\_\_----------------------------  
INSTRUCTIONS BELOW

Sometimes you will need to test more than one thing at a time. The logical and operator (&&) returns true if and only if the operands to the left and right of it are true.

The same effect could be achieved by nesting an if statement inside another if:

```auto
if (num > 5) {
  if (num < 10) {
    return "Yes";
  }
}
return "No";

```

will only return “Yes” if num is between 6 and 9 (6 and 9 included). The same logic can be written as:

```auto
if (num > 5 && num < 10) {
  return "Yes";
}
return "No";

```

Instructions  
Combine the two if statements into one statement which will return “Yes” if val is less than or equal to 50 and greater than or equal to 25. Otherwise, will return “No”.

---

<div class="post-metadata">

**Author:** ![Dan\_Cio](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dan_cio/32/72058_2.png) [@Dan\_Cio](https://forum.freecodecamp.org/u/Dan_Cio)\
**Post date:** [November 19, 2017, 10:57pm UTC](https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920/2 "2017-11-19T22:57:01Z")

</div>

> [@teaglebuilt](#):
>
> return “no”;

Replace with `return "No";`

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [November 19, 2017, 11:49pm UTC](https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920/3 "2017-11-19T23:49:57Z")

</div>

I’ve 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](http://forum.freecodecamp.com/t/forum-code-formatting/25574) to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![Wookies-Will-Code](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/wookies-will-code/32/69296_2.png) [@Wookies-Will-Code](https://forum.freecodecamp.org/u/Wookies-Will-Code)\
**Post date:** [November 21, 2017, 8:26pm UTC](https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920/4 "2017-11-21T20:26:21Z")

</div>

> [@teaglebuilt](#):
>
> `};`  
> // Only change code above this line
> 
> `return "No";`
> 
> // Change this value to test

Seems like this one is just hanging out there as an executable statement (outside of the function, unless there is more code up above wrapping it in yet another code block.

-WWC

---

<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:34pm UTC](https://forum.freecodecamp.org/t/comparisons-with-the-logical-and-operator-is-not-working/159920/5 "2021-01-17T20:34:13Z")

</div>

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


