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 A Basic If Statement

Kevin Jervis
Kevin Jervis
2,600 Points

Conditional Statements

Hi Guys

I'm stuck on this task. Not sure if I'm on the right lines

Thanks Kevin

script.js
var isAdmin = true;
if (=== IsAdmin ) {
}
  alert("Welcome administrator");
var isStudent = 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>
Pavol Kocalka
Pavol Kocalka
9,961 Points

you can check if isAdminn is true and then add block of commands to be executed when it is true.

var isAdmin = true;
var isStudent = false;

if (isAdmin === true) {
  alert("Welcome administrator");
}

because we already have variable as a logical true, we do not need to add equality logical operator and write the program like this:

var isAdmin = true;
var isStudent = false;

if (isAdmin) {
  alert("Welcome administrator");
}
Curtis Vanzandt
Curtis Vanzandt
9,165 Points

Conditional statements test for booleans themselves. You could hard code that by putting "if (isAdmin === true) {}" as your condition. However, you can simply have your condition be the following in order to be a bit more concise: "if (isAdmin) {}"

2 Answers

Steven Parker
Steven Parker
231,236 Points

Statements controlled by the conditional must be between the braces. Also, when testing a boolean, you don't need a comparison operator (plus, comparison operators require something on both sides).

Kevin Jervis
Kevin Jervis
2,600 Points

That's great guys. Many thanks. I can see where I was going wrong now. Always something so simple :o)