Basic JavaScript - Comparisons with the Logical And Operator

I’ve tried what the video says to do and what people on here say to do and it’s not working. I have no idea what I’m doing wrong, anyone else???

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

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

  // 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Comparisons with the Logical And Operator

Link to the challenge:

This condition is impossible.

I’d ignore any video you found. They often get out of date.

I thought so because I even tried it this way like a comment said from the help thread and still didn’t work. Is there an updated way to do it?

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

if (val >= 24 && <= 51) {
{
return “Yes”;
}
}

// Only change code above this line
return “No”;
}

testLogicalAnd(10);

or am I just dumb :rofl: :sweat_smile:

This is close but the endpoints of the interval you need are not correct.

1 Like

The instructions don’t talk about 24 or 51?

Also, your second condition is incomplete

You want to be between 25 and 50, including those values. Can you be less than 25 an be in that range?

No the instructions don’t I just saw someone in the help thread say that’s what they did so I thought I might as well try that too. The second condition you’re suppose to delete according to the video but as you said it could be out dated but even when I did both it still didn’t work.

Ignore the video. It’s confusing you.

Can you state two separate conditions that every number in the range from 25 to 50 must satisfy?

Every number needs to be bigger than or equal to ___

Every number needs to be smaller than or equal to ___

If you have those two conditions, then you put the && between those two conditions to get the if statement to work as you want.

100% is confusing me lol.
wait a sec I think I got it let me see

1 Like

Ok so I’m so close I got all checks except for 2 that say " you should only use the && operator once " and " you should only have one if statement "
This is what I have so far

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

if (val <= 50) {
if (val >= 25) {
return “Yes”;
}
}

// Only change code above this line
return “No”;
}

testLogicalAnd(10);

This is the part where you take these two separate conditions and literally put && in between them.

so close! now its just saying I need one “if” statement only. In the video the dude just deleted the section underneath but doesn’t work when I do it :face_exhaling: this is the part that confused me the most

What did you try after I suggested

I just deleted the if from the first line and it did nothing so I put it back and deleted the second if on the second line also did nothing. Hope that makes sense.

So you did not add a && anywhere? Hmm, not adding the && can’t work.

The example of using && given is

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

You must do something that looks like that

no I did exactly what you said and put the && all I have left to do is get rid of one of the ifs is what it’s saying

Can you show your new code that uses the &&

Sure and also thanks for helping and being so patient lol

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

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

// Only change code above this line
return “No”;
}

testLogicalAnd(10);

you see how there is two “if’s”?

It looks like the outer if is redundant to me.