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

Val Ki
Val Ki
1,997 Points

Please help!

I keep getting an error because I'm not sure how to combine the iAdmin and the isStudent statements and set them equal to "false". I'm not sure where to start with this so any help may help. :)

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>

3 Answers

Steven Parker
Steven Parker
231,275 Points

You're actually very close, but the plain "else" doesn't take any conditional clause. It doesn't need one since it handles any case not already covered by the previous "if" and "if else"s.

Also remember to close the last "if else" block with a brace.

Steven Parker
Steven Parker
231,275 Points

You still need a close brace ("}") before the last "else".

The wording of this question makes it sound more complicated than it is, all you need is the 'else' statement since the other options have been checked in the previous statements:

  else {
    alert("Who are you?");
}

Cheers.

Val Ki
Val Ki
1,997 Points

Hi Martin,

I copied and pasted your code and I'm still getting an error message. :(

Val Ki
Val Ki
1,997 Points

This is what I'm inputting:

var isAdmin = false; var isStudent = false;

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

Val Ki
Val Ki
1,997 Points

OMG! Thanks so much! I finally got it!