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