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 JavaScript Basics (Retired) Making Decisions with Conditional Statements Review Boolean Logic

Jason Kang
Jason Kang
2,749 Points

Why won't && work for this quiz problem?? Help please

if ( username === '' password === '') { alert("Password or user name is missing"); }

So I found that the answer is || and not &&. I want to understand why && will not work. Since it says Password OR user name is missing, can't either the username and password BE true while the other be false? The username can be true and password can be false, vice-versa. In that case, true && false = false and false && true = false. Doesn't the alert in the problem mean false since it says Password or username is missing? Please help.

1 Answer

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

This is what you were trying to do.

alert("Password or user name is missing"); //Focus on word or

If you used if ( username === '' && password === '') that would mean

alert("Password AND user name is missing"); Because in JavaScript && stands for AND.

This is how AND works, consider A && B.

A && B is true only if both A, B is true every other case evaluates to False. However,

A || B, which stands for A or B, evaluates true when A, B is true, A is true, B is true.

So in a nutshell A || B reflects more on what we meant by alert("Password OR user name is missing");

Hope you can see the difference between two.