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

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 m

These challenges are really getting me this go around!

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'.

Can someone please help me out. I have already rewatched the video AND written the code in the workspace for reference. ??? Help!

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

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

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey,

the problem is that you're replacing the existing if clause but instead you have to add an else if clause for the students like so:

var isAdmin = false;
var isStudent = true;

if ( isAdmin ) {
    alert('Welcome administrator')
} else if ( isStudent ) {
    alert('Welcome student')
}

I hope that helps! :)

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You weren't meant to change the administrator part. You're simply adding a part to say what happens if it's a student that's looking at this. Here... take a look at this code.

var isAdmin = false;
var isStudent = true;

if ( isAdmin ) {
    alert('Welcome administrator')
} else if (isStudent) {
  alert('Welcome student')
}

Thank yuu.....again! :)

Daniel Gauthier
Daniel Gauthier
15,000 Points

Hey again Nicollette,

Your last attempt was inspired, but you were overthinking it.

Checking out this working code:

var isAdmin = false;
var isStudent = true;

if ( isAdmin ) {
    alert('Welcome administrator')
} else if(isStudent === true) {
  alert("Welcome student");
}

The takeaway from this particular challenge is just knowing how to include an else if as an additional condition.

It'll get a lot easier the more you work with it.

Good luck!

Thank you! I think I am just tired and need a mental break!