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 Add an Else If Clause

ROHITH CHITHRANGADHAN
ROHITH CHITHRANGADHAN
9,006 Points

why i am being asked to add Else if clause even after adding else if to the conditional statement?

The task was to add an else if condition and i did it as well but still i'm get an error and it i being asked to add else if clause. What does this mean is the statement different from clause?

script.js
var isAdmin = false;
var isStudent = true;

if ( isAdmin ) {
    alert('Welcome administrator');
}   else if ( isStudent === true ) {
    alert("Welcome student");
}
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>

You don't need the comparison operator in the conditional. the conditional itself is checking for it to be true inherently.

2 Answers

Steven Parker
Steven Parker
229,644 Points

Your code is correct and will pass the challenge. The "clause" is simply the combination of the conditional and statement.

Justin also makes a good point, it is not necessary to compare a boolean with "true", just naming it is enough (as was done with "isAdmin" in the provided code).

ROHITH CHITHRANGADHAN
ROHITH CHITHRANGADHAN
9,006 Points

Thanks Steven and Justin. I tried it out again and passed with same code. I don't understand what went wrong before. And you are right Justin comparison operator weren't necessary.