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 a Final Else Clause

Marc Sirianni
Marc Sirianni
1,216 Points

else if else statement error

Not sure how to include two variables... i.e. if this AND this equals false.

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

if ( isAdmin ) {
    alert('Welcome administrator');
} else if (isStudent) {
    alert('Welcome student');
} else (isAdmin + isStudent === false{
  alert('Who are you?');
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>

2 Answers

Hi Marc,

You cannot pass a conditional to a final else statement. So you just write the else and what should happen inside.

Like this:

var isAdmin = false;
var isStudent = false;

if ( isAdmin ) {
    alert('Welcome administrator');
} else if (isStudent) {
    alert('Welcome student');
} else {
  alert('Who are you?');
}

With that begin said, you cannot write a double check like this:

else (isAdmin + isStudent === false{

Besides the fact that it's not closed with a bracket and you cannot give a conditional to an else-statement, like i said above, You would write a double check like this:

if (isAdmin === false && isStudent === false) {
//do something
}

Elian

I suggest you turn the statements around.

if the person is admin else if the person is not admin and not student else

That way you tackle the empty else statement and from a logical perspective it makes sense the person is either admin or student or something else. In the example I gave you basically check if they are admin, if they are something else and if both of that is false the only conclusion left: must be student.