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

booleans

Im stuck on the boolean objective :(

script.js
if ( ) {
    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

andi mitre
STAFF
andi mitre
Treehouse Guest Teacher

Hey Louis, since true is a boolean itself, you can add true inside the if statement like so:

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

Cheers

A good way to do this exercise and writing all conditional statements is to say the conditional statement out loud. ie. if this is true then do this, if not true then do something else. so in that sentence you have your conditional statement and if else clauses. so in your case your code should look like this:

if (true) {                        //if this is true
    alert('This is true');    //then do this code 
} else {                         //if not true, then do something else 
    alert('This is false');   //something else
}

I hope this helps.