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 trialPhil Ward
4,204 PointsJavaScript 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'); }
var myStatement = true;
if (myStatement === true) {
alert('This is true');
} else {
alert('This is false');
}
<!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
28,736 PointsWhat 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
4,204 PointsPhil Ward
4,204 Pointsthanks! worked a treat. a little silly as the prior video specifically covers creating boolean variables then using them in IF statements.
Russell Christensen
4,264 PointsRussell Christensen
4,264 PointsI'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.