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 trialKevin Jervis
2,600 PointsConditional Statements
Hi Guys
I'm stuck on this task. Not sure if I'm on the right lines
Thanks Kevin
var isAdmin = true;
if (=== IsAdmin ) {
}
alert("Welcome administrator");
var isStudent = false;
<!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>
Curtis Vanzandt
9,165 PointsConditional 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
231,236 PointsStatements 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
2,600 PointsThat's great guys. Many thanks. I can see where I was going wrong now. Always something so simple :o)
Pavol Kocalka
9,961 PointsPavol Kocalka
9,961 Pointsyou can check if isAdminn is true and then add block of commands to be executed when it is true.
because we already have variable as a logical true, we do not need to add equality logical operator and write the program like this: