Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
218,694 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)