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

Phil Ward
Phil Ward
4,204 Points

JavaScript boolean task not completing

the correct alert message is appearing as per the task, but its not passing. i've tried both just putting the variable in the IF statement and with === true. is there a bug with the task?

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

script.js
var myStatement = true;
if (myStatement === true) {
    alert('This is true');
} else {
    alert('This is false');
}
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

geoffrey
geoffrey
28,736 Points

What you did is correct, but the exercise just asks to add true inside the parenthesis of the if statement, there is no need to store it inside a variable such as statement. I've just tested it.

if (true) {
    alert('This is true');
} else {
    alert('This is false');
}
Phil Ward
Phil Ward
4,204 Points

thanks! worked a treat. a little silly as the prior video specifically covers creating boolean variables then using them in IF statements.

Russell Christensen
Russell Christensen
4,264 Points

I'm glad I came across this thread! I, too, read the code challenge thinking that it was asking for a variable to be created specifically because of the previous video. Perhaps the question could be restated for better clarity.