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

JavaScript Else If Challenge

I'm not understanding the wording of this challenge too much. It's saying test to see if the isStudent true by adding an else if statement.... But I thought you only added an Else If statement when there were more than 2 possible outcomes like if it's 1 then do this, else if it's 2 then do this, else it's 3 do this... Any help on this would be appreciated.

Also I had to refresh the page to get the "Ask a Question" button to work so you'll have to open the url I provided below to see my original code.

http://www.clipular.com/c/5265431730323456.png?k=JFd8QA-NhAJz70DEbvKr386-JOQ

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

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

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Ira.

I understand what you mean, you are basically saying that both cases are all covered in this example and we could only use an else clause, but also an else if clause sounds right here as the code provided checks if the person isAdmin (false), then the immediately following code does not run. Then with the else if clause we check ifStudent (true as per code provided), so what we will put inside the following {} will get execute.

Apart, from the doubt you have, have you managed to pass the code challenge?

Yea I ended up figuring it out after taking a break. I was a little confused at first but it all made sense at the end.