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

Charles Harpke
Charles Harpke
33,986 Points

Add a Boolean value to the condition in this conditional statement. Use a boolean value that will result in the message

Not quite understanding the question..... here is my code:

var Admin = true;
var Student = false;
if ( Admin = true) {
    alert('This is true');
} else {
    alert('This is false');
}

the error is receive is this:

Bummer! Did you add true inside the parentheses of the conditional statement?

10 Answers

Andrew Shook
Andrew Shook
31,709 Points

Charles, you are using the assignment operator(i.e. setting a variable equal to) and not using a comparison operator ( == or ===) in your if statement. That is why the challenge won't pass. Technically, you don't need to use a comparison operator here, you could just put the variable that equals true and the if statement will pass.

Robert Mckay
Robert Mckay
11,089 Points

This needs to be modified - to include the ability to put in a boolean value through a variable. Or the question needs to be changed so that the user knows that it is actually not looking for a variable to be set to a Boolean value.

Rickie Thornley
seal-mask
.a{fill-rule:evenodd;}techdegree
Rickie Thornley
Full Stack JavaScript Techdegree Student 7,440 Points

I agree - This does not specify (in 2017) that the user need not create a value for this. Theres no need to be cryptic, real work places are not cryptic in what they are asking you to develop for purposes to avoid confusion to get the software they need.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Charles;

For this challenge think simplify when it comes to the task instructions and especially with the challenge error message, it is rather explicit in what you need to do.

Post back if you are still stuck.

Ken

I feel I've done everything correctly, but I am still getting the same error as Charles. Thoughts?

```var foo = true;

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

Thanks Charles. This was helpful

Mihai Tabla
Mihai Tabla
6,493 Points

the correct answer to this was

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

Shaun Wong
Shaun Wong
14,489 Points

Thanks, this worked.

Mihai Tabla
Mihai Tabla
6,493 Points

stil i haven't managed to pass this task.

my code:

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

What do i do wrong ?

Andrew Shook
Andrew Shook
31,709 Points

Change the value of aGuess to true.

For everyones viewing pleasure:

if (true ) {
    alert('This is true');
} else {
    alert('This is false');
}
stephenallison
stephenallison
8,559 Points

The question simply ask for the Boolean value that will result in a statement change. By placing "true" in the if statement satisfies the equation.

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

Charles Harpke
Charles Harpke
33,986 Points

Ah...thank you...yes...I didn't use the comparison operator...just the Boolean and voila....

jonpaul uritis
jonpaul uritis
6,669 Points

Jeffs answer works : if (true ) { alert('This is true'); } else { alert('This is false'); }

however ('true' == true) or any combination of a statement that evaluates to true doesn't. I tried 15 or so. Just letting everyone know

Midhun Chandran
Midhun Chandran
9,414 Points

Ensure that you type in 'true' and not 'True'

Hence the correct statement is: if (true) { alert('This is true'); } else { alert('This is false'); }

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