Comparisons with the logical And Operator is not working

this is my code:

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:

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:

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”.

1 Like

Replace with return "No";

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 to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

markdown_Forums

1 Like

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