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

eva rios mb
PLUS
eva rios mb
Courses Plus Student 3,948 Points

Boolean basic code

What is wrong with this?

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

script.js
var bigGuy = true;
if (bigGuy) {
    alert('This is true');
} else {
    alert('This is false');
}
index.html
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="UTF-8">
  <title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 Points

Hi Eva, This code is well formed (no errors) and produces an alert box that displays the message "This is true". Are you expecting a different result?

Hi,

The following code worked in the code challenge for me

var booleanValue = true; 

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

The conditional statement takes the value of the variable but not the variable itself. Im not sure why but you should be able to pass the challenge with the code above!

Cheers

4 Answers

Dale Severude If you look in the right hand corner there is a box that says "View Challenge" and you can actually go to the challenge. I didnt know this either but it has been super helpful for me to do the challenge and then give an answer.

Just in case you didnt know because I didnt know for a long time!

Happy coding

Seth Kroger
Seth Kroger
56,413 Points

Normally that should work. I've tried a couple of different ways myself and the challenge wants the specific answer if (true)