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
Thomas Greer
8,257 PointsThere was an error with your code: SyntaxError: Parse error
Help me with my code challenge please. What is a Parse error?
5 Answers
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Pointsif ( isAdmin ) {
alert('Welcome administrator');
} else if (isStudent) {
alert('Welcome student');
} else (false) {
alert('Who are you?');
}
The problem with this code is that the final 'else' clause does not take a condition, it simply catches whatever has not been caught before it. So simply change 'else (false) {' to just 'else {' :
if ( isAdmin ) {
alert('Welcome administrator');
} else if (isStudent) {
alert('Welcome student');
} else {
alert('Who are you?');
}
Thomas Greer
8,257 PointsThat makes sense. Thank you very much!
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 PointsA Parse error means the there is something wrong with the syntax of your code, perhaps a missing bracket, parenthesis, curly brace. Also possibly a missing semicolon, maybe an accidentally inserted character out of place. It is just something that the javascript interpreter cannot make sense of. If the error gives you a line number, look at that line number and see if something appears off.
Alternatively, you can post your code and we can point it out.
Saira Bottemuller
Courses Plus Student 1,749 PointsThank you Nicholas, and thank you Thomas for asking this - I took that challenge a while back and had the same trouble - BUT it was the reason I started remembering the difference in syntax for else if -vs- else. It's the little things, you know? :)
Mireille Bonapart
5,254 PointsThanks Nicholas, I also struggled with this one. I really appreciate your explanation on the parse error message. Apparently I forgot the question mark in the question: "Who are you?" that caused my code not to pass :(
Lauren Sithole Gadyadza
6,659 Pointsthank you so much i struggled on this one too yet i was very close, had written a condition(false) and also had missed a question mark. thanks again, best answer indeed
Thomas Greer
8,257 PointsThomas Greer
8,257 PointsThis is the the challenge: Add a final else clause to this conditional statement so that if the isAdmin variable and isStudent variables are both false an alert opens with the message "Who are you?" And this is the code I have:
var isAdmin = false; var isStudent = false;