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 Combining Multiple Tests Into a Single Condition

Or conditions

if ( agree === 'yes' || 'y') {}

It's ok I know this is not the right syntax, but can't 'y' return bool true ?

2 Answers

Stephan Olsen
Stephan Olsen
6,650 Points

You can definitely use booleans in your conditions. You could do something like this:

var y = true;
var agree = prompt();
if ( agree === 'yes' || y) {


Now the above example does not make much sense in a real life project, as I've statically set y to be true, therefore the code will always be run.

nico dev
nico dev
20,364 Points

Hey Nikica Maksimovski ,

Actually, that if will evaluate if the whole expression is true, that is the whole agree === 'yes' or the whole agree === 'y' are true. If only one of them (or even both) is/are true, it will execute the code inside the curly brackets. Otherwise, it will skip it altogether.

So what matters here is not if 'y' is true, but if it may be equal to agree. We would probably know better how to answer, and hopefully help you, if you provide a little more context, like for example, what is 'agree'? I suspect it is a variable that comes from some sort of input like 'prompt', right? Looks like it, at least.

But if, for example, the 'agree' is indeed some form of input, the condition will be true (and therefore executing the code) if either 'y' or 'yes' are entered into the prompt or sort of input. (NOTE: Not if they are capitalized in this case).

Hope that somehow helps, but otherwise, it would be great to know better what you want to do, and what you have done so far, for us to be able to help you.