Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
MOD
Cameron Childres
Treehouse Moderator 11,719 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.

Joseph Yhu
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Yhu
PHP Development Techdegree Graduate 48,463 Points

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 :)