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 Making Decisions in Your Code with Conditional Statements Add an 'else if' Clause

Why is my code wrong?

I don't know why my code is wrong. Please help.

script.js
const isAdmin = false;
const isStudent = true;
let message;

if ( isAdmin ) {
  message = 'Welcome admin';
} else if ( isStudent = true ) {
  message = "Welcome student"
}

3 Answers

Cameron Childres
Cameron Childres
11,820 Points

Hi Xajx,

A single equals sign is an assignment operator which is used for setting values (like setting the variables in the first two lines, or setting the value of the message). Here you want to test values, so use the comparison operator "==". This tests if one thing is equal to another.

Alternatively you could leave out the comparison entirely and just have isStudent as the condition of the else if clause on its own. Since its value is true this will be the same as saying else if (true). You can see this in the if statement where isAdmin evaluates to false.

Remember that the equality operator is two equals signs, not just one. Actually, you don't even need the == true part; you can just type else if ( isStudent ) {.

Oh right! Thanks Cameron and Joseph! Appreciate the help :)