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

Emil Ty
Emil Ty
5,844 Points

Not sure what I'm doing wrong.

error says 'Welcome student' is not in message, but it is? I'm sure I'm missing something small...but I can't find it...

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

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

this works :)

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Always leave the original code as-is unless specified. all you need to do is test isSdudent, not isStudent == true. Doing it that way will automatically check for the value true:

var isAdmin = false;
var isStudent = true;

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

I'm stuck on the next part after this. I don't know what to put. else(){ } Am I suppose to put something in the ()?

Yes you add whatever condition needs to be true to run the code inside the {}. So you have if (isAdmin) {do this}

else (????) do this

On this challenge there only is one other option so you could leave it blank, i think it should work either way.