Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ireneusz Kopta
Ireneusz Kopta
6,212 Points

operators

function paternChck(numbers){
    if(numbers.length !== 8 || numbers.length !== 7 ){
        return false;
    }
}

why is that code not working? Why do i need to use less or greater here to make the code working.

3 Answers

Ireneusz Kopta
Ireneusz Kopta
6,212 Points

when passing string like "12345678"

Ireneusz Kopta
Ireneusz Kopta
6,212 Points

Okey I think I found the solution :) " NOT acts on one boolean expression (rather than two): ! means NOT. Results in true if the expression is false."

God that one gave my a headache :)

Hi Ireneusz,

What is this function supposed to do? Maybe you can get help with using better logic if you describe what it's supposed to do.

The ! in javascript has multiple uses. The way you have described it in your answer is as the logical NOT operator and not the same as how you're using it in your code.

! can act as a unary operator where it takes 1 operand.

var someBoolean = true;
!someBoolean; // this evaluates to false

How you're using it in your code, !==, is as the strict not equal to comparison operator which requires operands on both sides.

So numbers.length !== 8 is going to evaluate to true if the length is not equal to 8.

9 !== 8; // true
8 !== 8; // false

What your if condition is saying is "if the length is strictly not equal to 8 OR the length is strictly not equal to 7"

Your if condition will always be true because at least one side of the logical OR operator will always be true. In order to be false, both sides have to be false, false || false which means the length has to be both 8 and 7 at the same time, which it can't be.