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 trialliyiyang
Courses Plus Student 2,880 PointsThe message popped up was the same content as the question requested (This is true) However, I still can't pass?
I've tried
var xxx = true; if (xxx) { } or var xxx = true; if (xxx = true) or var xxx = true; if (xxx === true)
The messages popped up were always correct("This is true") But I still can't pass the challenge. Can anyone tell me why? Thanks a lot!
var correctGuess = true;
if ( correctGuess ) {
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
Nathaniel Nasarow
10,291 PointsThe code challege is looking for a boolean value, not a variable. Remember, a boolean value is simply true or false. Try removing the variable and using just the true or false boolean in the if statement.
liyiyang
Courses Plus Student 2,880 Pointsliyiyang
Courses Plus Student 2,880 PointsNow I get it. Thank you so much for your help!
Nathaniel Nasarow
10,291 PointsNathaniel Nasarow
10,291 PointsNo problem. I think this exercise is simply there to show you the use of true and false and what they do. I don't think there is any actual relevant use for making an if statement that only looks for "if (true) {do this}". Rather, a variable will be checked to see if it is true or false.
At least, that's what I think with my limited knowledge.