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

Ben Wilburn
Ben Wilburn
1,307 Points

I cant seem to figure this else if challenge out.

I have tried several different layouts of code but all it ever tells me is that there is a syntax error. I've gone back and look at the syntax in the video several times. I have even put the code into Visual Studio for it to point out my mistake and all is says is to put a ; in a place that Dave says not to put it (I did anyway & it created more problems). I don't see the error. Maybe a different set of eyes can point it out for me.

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

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

the > weren't in the original code.. its just something else I tried and watched fail. So, analyze the code minus the ">".

3 Answers

Tushar Singh
PLUS
Tushar Singh
Courses Plus Student 8,692 Points
var isAdmin = false;
var isStudent = false;

if ( isAdmin ) {
    alert('Welcome administrator');
} else if (isStudent) {
    alert('Welcome student');
} else {
  alert("Who are you?");
}
Rohit Tolawat
Rohit Tolawat
8,277 Points

Hi Ben, The issue with your code at first glance seems to be the following: After the final else clause, there should not be any conditional statement. The general structure of if.. else if.. else clause is: if (cond){} else if(cond){} else if(cond){} else {}

This seems to be violating here. Please try with the suggested solution and update if it works out well for you.

Thanks, Rohit.

Ben Wilburn
Ben Wilburn
1,307 Points

Thank you Tushar, I had been at it for a while and I couldn't remember all the rules. Your suggestion worked! Appreciate the help!