Logical and Operator help

Tell us what’s happening:
Hello everyone,
I’m having some issue with what I’m doing wrong in this code. Initially I had, the values swapped (val >= 25 && val >= 50) and it wasn’t passing. I saw that in the console.log on the bottom it has an arrow pointing to the 10; portion so I tried changing that value to the different test values in the problem. It didn’t do anything. Finally I looked up the problem and entered it exactly like the solution and I’m still stuck.

Any ideas what I’m doing wrong?

Your code so far


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

if (val <= 50 && val >= 25) {

// Only change code above this line
return "No";
}

testLogicalAnd(10); 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Comparisons with the Logical And Operator

Link to the challenge:

you have two opening { and only one closing }, so it is pointing to the end saying you have never closed the function - you are missing a } somewhere

and your function should also return “Yes” sometimes, but your function can’t do that

What do the failing tests say? What exactly are you trying to test for?

I do see one syntax error in your code. Count your opening and closing braces ({ and }).

Thank you both for pointing that out. I must have somehow omitted that and totally didn’t see the syntax error. I went ahead and added a } after return “No”;
but no luck on getting it to actually give me a yes or no.

// running tests

testLogicalAnd(0)

should return “No”

testLogicalAnd(24)

should return “No”

testLogicalAnd(25)

should return “Yes”

testLogicalAnd(30)

should return “Yes”

testLogicalAnd(50)

should return “Yes”

testLogicalAnd(51)

should return “No”

testLogicalAnd(75)

should return “No”

testLogicalAnd(80)

should return “No” // tests completed

You should share your most recent code. The last code that you shared never returns “Yes”.

function testLogicalAnd(val) {

  // Only change code below this line

  if (val <= 50 && val >= 25) {

   return "Yes";

      

  // Only change code above this line

  return "No";

    }

}

testLogicalAnd(10);

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Both your return "Yes" and your return "No" are inside the if block.

1 Like

Thank you! That did the trick! Can’t believe I missed that I will make note of the backticks.

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

  if (val <= 50 && val >= 25) {
   return "Yes";
  }
  

  // Only change code above this line
  return "No";
    }


testLogicalAnd(10);

Congratulations on working through the problem and figuring it out! Happy coding.