Comparisons with the Logical And Operator helpview

Comparisons with the Logical And Operator helpview
0

#1

Tell us what’s happening:
how i can set the value of using logical and operator?

Your code so far


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

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

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

}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/comparisons-with-the-logical-and-operator/


#2

The order of your if checks is incorrect. You’re checking 0-23 first, then checking 24-50+. So if 30 is passed in, it will not pass the first if and return “No”, when it should be “Yes”.

If you carefully re-read the instruction, it reads the same way you should structure your 2 checks.
Edit: @aditya_p feedback below is also spot on, i misread the exercise. You’ll need to merge them into a single if using &&


#3

The sole purpose of this challenge was to to use && operator and not two if statements.
Now rethink your proble and see if you can solve it.
(Remember to read the instrucions on left pane of the challenge.)
Hope this helps.


#4

i dont know what i am doing in program plz help the solution…


#5

Your if statement should look like second example given in the instructions where only one if is used.
Something like:

if(...use && operator here...){
  return "Yes";
}

Does this help?