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 trialAlana Warson
5,296 Pointselse if clause I cannot get this ... there is a small thing I'm missing...
const isAdmin = false; const isStudent = true; let message;
if ( isAdmin ) { message = 'Welcome admin'; }else if (isS
const isAdmin = false;
const isStudent = true;
let message;
if ( isAdmin ) {
message = 'Welcome admin';
}else if (isStudent) {
message = 'Welcome student";
else (false)
5 Answers
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Alana,
You’re really close here.
Two things I’m seeing.
The first is that you have mixed quotes surrounding your Welcome student string in the code example you’ve provided. It doesn’t matter if you use single quotes or double quotes, but whichever one you start with, that’s the one you have to end your string with.
The second thing is you don’t have a matching curly brace to signify the end the code block for the else if statement.
You don’t need the else branch for this challenge, but that shouldn’t throw off your code.
Hope that helps. If not, let me know.
Alana Warson
5,296 PointsBrandon,
Thank you for the help. I really appreciate it!
Alana Warson
5,296 PointsI just changed what you said to change and the error message is: "Did you add an 'else' statement at the end?
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 Pointsconst isAdmin = false;
const isStudent = true;
let message;
if ( isAdmin ) {
message = 'Welcome admin';
} else if (isStudent) {
message = 'Welcome student';
} else (false)
Make sure your code looks like the code snippet above. It’s the same as the code snippet you provided except I’ve changed the quote after admin, added an ending curly brace, and added some white space for readability. This code passed for me.
The code below also passed for me.
const isAdmin = false;
const isStudent = true;
let message;
if ( isAdmin ) {
message = 'Welcome admin';
} else if (isStudent) {
message = 'Welcome student';
}
It doesn’t really matter if you have the else statement there or not. It doesn’t do anything, so it’s probably less confusing if you removed it, but based on the error you’re getting... I’m thinking that the unit test for this challenge can’t reach your else/else if block.
Alana Warson
5,296 PointsHello Brandon,
Thank. you again for your help. I will leave out the else clause at end but Im afraid it will error, What happens if i never can get this correct? What do I do. .... keep going to the next series?
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHey Alana,
Make sure your code follows this format.
if (/*some expression */) {...}
else if (/*some expression */) {...}
//else {...} // you can leave out this statement if you choose
Based on your last error message, I’m guessing that you don’t have one of these: } at the end of the code block for your if
statement.
const isAdmin = false;
const isStudent = true;
let message;
if ( isAdmin ) {
message = 'Welcome admin';
else if (isStudent) { // there should be a right curly brace } before the else if keyword to end the if statement
message = 'Welcome student';
}
I think you should look over your code really carefully to make sure yours looks like one of my examples in the messages above. If that doesn’t work you could try retyping your code into the browser console to see if you get an error message that offers more guidance.
If none of that works, then yes, move forward. But once you gain a little more knowledge and experience, revisit this challenge and squash that bug.
Alana Warson
5,296 PointsI will try this. Thank you again for all your help. :)