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

I am getting the alert box this is true but still it's not letting me pass this challenge. Why?

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

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

the code seems to be working and the 'This is true' alert pops up.

script.js
var hello = "true";
if (hello === "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>

2 Answers

Hugo Paz
Hugo Paz
15,622 Points

Hi Lynard,

You are supposed to use a boolean value and not a string.

A simple solution would be:

if (true) {
    alert('This is true');
} else {
    alert('This is false');
}
Demian Martinez
Demian Martinez
2,985 Points

I had the exact same problem thanks for clearing this up!

Hi Hugo, thanks for the quick reply. That one works.

I get it now, "Boolean value" is just either "true" or "false" . So the challenge is just asking you to choose from true or false, not to write a Boolean expression.

Thanks again.