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 Booleans

Boolean value to the condition in this conditional statement

I am unclear on what exactly this problem is asking for? I have tried several different things and am unable to determine what it is asking for? This is my most current attempt:

var x = false;

if ((x) === 'true') { alert('This is true'); } else { alert('This is false'); }

The error messages I am receiving are keep referring to including true in parenthesis....

6 Answers

Tommy Gebru
Tommy Gebru
30,164 Points

Hi Rachel,

Have you tried to insert the boolean values : True or False into the conditional statement.

if (condition) {
    execute;
} 
else {
    execute;
}

In this case the challenge is just looking for a simple value to complete the if statement.

Hope this helps;)

Erik McClintock
Erik McClintock
45,783 Points

Rachel,

This challenge is telling you to put something in the if statement that will result in it evaluating to its true state, which will output the sentence "This is true" in an alert box. All you need to do is create something that is true and pass it to the statement.

Currently, you have two things incorrect in your code.

1) You need to remove the parenthesis from the variable 'x' in your if statement and remove the single quotes from the value 'true':

You have:

if((x) === 'true') {
}

You need:

if(x === true) {
}

Putting parenthesis around your variable 'x' is just incorrect, but the single quotes around the value 'true' is just not matching up with what you're setting 'x' equal to. If you have quotes (whether single or double) around a value, you are declaring to JavaScript that it is a string. You are not setting the value of 'x' equal to a string, you are currently setting it equal to the boolean value of false. If you had set it to "false" (with quotation marks), then you would be setting it to a string, and thus would check it against a string value in your conditional. In this case, you're setting it to a boolean, so you want to check it against a boolean.

2) You're not evaluating a statement that is true. You currently have the value of 'x' set to false, and you're checking if the value is true in your if statement. Since it is NOT true, this if statement would evaluate to false, thus displaying an alert box with "This is false" in it.

Fix those errors and you're good to go!

Erik

Erik McClintock
Erik McClintock
45,783 Points

Rachel,

Try what Tommy has suggested and just put true into the conditional, like follows:

if(true) {
...
} else {
...
}

Sometimes these challenges can be suuuuper picky in what they're looking for.

Additionally, I don't believe the preview will do anything for this challenge. Just submit the code and see what happens!

Erik

Thanks for the help Erik and Tommy! Unfortunately, I am still not understanding what I am doing wrong here...

So I ditched the extra parenthesis, and played around with making a few changes. No matter what I do when I preview my file it does nothing.

var x = 6; var y = 9; if (x < y === true) { alert('This is true'); } else { alert('This is false'); }

I also tried this:

var today = 'Friday'; if (today === 'Friday') { alert('This is true'); } else { alert('This is false'); }

Any additional advice?

Thank you very much, that did work. I appreciate you walking me through the problem as well though.

sorin vasiliu
sorin vasiliu
6,228 Points

This exercise is written in a way that students (complete beginners) fail to understand. I have gotten this feeling throughout the entire course. I think the teacher forgets that we are complete beginners. Anyway, I'm sure that the course can be made more "learning friendly".