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

Hello. Im getting an error here, but to me, everything seems fine? Is my code wrong, or is it a bug in the quiz?

Check my code, to me it seems right! "else" is present as it should. Semicolons was there from the start

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

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

This is the answer i get when i check the code:

Bummer: Are you sure you put an "else" statement? (paraphrased)

also when i run the code, the program runs fine, i get an alert saying "Who are you?"

1 Answer

Steven Parker
Steven Parker
231,271 Points

This code looks OK to me. So I tried copy/pasting it directly into the challenge, and it passed!

Try again?

Also, while it doesn't affect the program (or passing the challenge), there's no advantage to removing the semicolons. In fact, even when they aren't necessary, it's considered a "best practice" to place them at the end of every statement.

Thanks for the answer and the tip. I jumped to the next challenge, probably a bug it seems :(.