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 trialNeta Gorelik
Courses Plus Student 3,184 Pointsthe code is good var over18 = true; if (over18) {alert('This is true');} else {alert('This is false');} doesn't pass
tryied both: var over18 = true; if (over18 === true) { alert('This is true'); } else { alert('This is false'); }
and
var over18 = true; if (over18) { alert('This is true'); } else { alert('This is false'); }
and
var over18 = true;
if (over18 == true) { alert('This is true'); } else { alert('This is false'); }
The code works, but quiz gives error
var over18 = true;
if (over18 === 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>
2 Answers
Hayes McCardell II
643 PointsUnfortunately, it looks like this one encourages over thinking it. Here's the code that passed the objective, in its entirety.
if (true ) {
alert('This is true');
} else {
alert('This is false');
}
Jacob Mishkin
23,118 PointsHayes is correct, But what is also important is the strictness of the code challenges. you have to do what they require or you will not pass. Like in your question. the code challenges states:
Add a Boolean value to the condition in this conditional statement. Use a Boolean value that will result in the message "This is true" appearing in an alert box.
although what you have is correct and valid, the code challenge ONLY wants a Boolean value where as you have a variable and a Boolean value. It can be tricky to know what the challenge really wants sometimes, but just make sure you answer the question to the T, and NOT add anything more then what its asking for.
Neta Gorelik
Courses Plus Student 3,184 PointsThanks, will keep that in mind. It looked strange to me too, as I noticed the quizzes are very precise, but just couldn't see anything wrong with my code. Thanks for your guidance.
Jacob Mishkin
23,118 PointsHonestly, there is nothing wrong with your code at all, its just not what the challenge wanted.
Neta Gorelik
Courses Plus Student 3,184 PointsOh, I know the code is fine, wasn't stressing about that :) Got confused by the question itself I guess.
Neta Gorelik
Courses Plus Student 3,184 PointsNeta Gorelik
Courses Plus Student 3,184 Points:-) Ha ha , you right, overthinking it :)