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 an Else If Clause

Emilie Munthe-Kaas
Emilie Munthe-Kaas
2,485 Points

Can't get code challenge to work..

No matter what I try, I can't seem to get it to be accepted. It works fine in preview, but when I 'check work' it says "Bummer! Did you add an 'else if' clause to the conditional statement?"

The question reads as follows: Add an else if clause that tests to see if the isStudent variable is true. If it is then open an alert dialog with the message 'Welcome student'.

And everything before the "else if" I wrote was there already.

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

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

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Emilie,

I was able to reproduce your problem, and the challenge editor seems to not like the fact that you have a tab instead of a space between the "}" and the "else if". If you put your cursor right before the "e" in else if, hit backspace to get rid of the tab, and put a space there instead, it will pass!

(Alternatively, you can copy your code from your forum post and use that, since tabs are automatically converted to spaces when they are displayed in the forum posts!)

I hope this helps!

Louise

I copy/pasted your code and it passed the challenge

Emilie Munthe-Kaas
Emilie Munthe-Kaas
2,485 Points

Thank you so much!! It was really bugging me!