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 trialxajx
6,553 PointsWhy is my code wrong?
I don't know why my code is wrong. Please help.
const isAdmin = false;
const isStudent = true;
let message;
if ( isAdmin ) {
message = 'Welcome admin';
} else if ( isStudent = true ) {
message = "Welcome student"
}
3 Answers
Cameron Childres
11,820 PointsHi 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
PHP Development Techdegree Graduate 48,637 PointsRemember 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 ) {
.
xajx
6,553 PointsOh right! Thanks Cameron and Joseph! Appreciate the help :)