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 trialVal Ki
1,997 PointsPlease help!
I keep getting an error because I'm not sure how to combine the iAdmin and the isStudent statements and set them equal to "false". I'm not sure where to start with this so any help may help. :)
var isAdmin = false;
var isStudent = false;
if ( isAdmin ) {
alert('Welcome administrator');
} else if (isStudent) {
alert('Welcome student');
else (isAdmin, isStudent = false){
alert("Who are you?");
}
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
3 Answers
Steven Parker
231,269 PointsYou're actually very close, but the plain "else" doesn't take any conditional clause. It doesn't need one since it handles any case not already covered by the previous "if" and "if else"s.
Also remember to close the last "if else" block with a brace.
Martin Zarate
10,723 PointsThe wording of this question makes it sound more complicated than it is, all you need is the 'else' statement since the other options have been checked in the previous statements:
else {
alert("Who are you?");
}
Cheers.
Val Ki
1,997 PointsHi Martin,
I copied and pasted your code and I'm still getting an error message. :(
Val Ki
1,997 PointsThis is what I'm inputting:
var isAdmin = false; var isStudent = false;
if ( isAdmin ) { alert('Welcome administrator'); } else if (isStudent) { alert('Welcome student'); else { alert('Who are you?') };
Val Ki
1,997 PointsOMG! Thanks so much! I finally got it!
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou still need a close brace ("}") before the last "else".