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

George Kuka
George Kuka
2,673 Points

Hello My programming is operating as it should and i am still getting an error...

var isAdmin = true; var isStudent = false;

if ( isAdmin === true) { alert('Welcome administrator'); } else if (isStudent === true) { alert('Welcome student'); } else (isAdmin + isStudent === false) { alert("Who are you?"); }

It is saying "Did you add a final "else" clause to the end of your code?" but when i run this code it all checks out... Even when i change the values to test if my other conditions are working and they are....

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

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

1 Answer

Hey George,

In your else clause. you don't put any statements beside of it. The else clause is for any other case not specified by if/else-if statements. Also, any time you are doing if/else-if statements, you don't use a + sign. You would use "&&" and separate the values out. Here is what your code should look like:

var isAdmin = true;
var isStudent = false;

if ( isAdmin === true) 
{
    alert('Welcome administrator');
} 
else if (isStudent === true) 
{
    alert('Welcome student');
}
else {
alert("Who are you?");
}
George Kuka
George Kuka
2,673 Points

Totally over thought that final else clause.

Thank you so much !

It happens to the best of us! :) You're very welcome.