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 trialNicollette Whitfield
4,526 PointsAdd an else if clause that tests to see if the isStudent variable is true. If it is then open an alert dialog with the m
These challenges are really getting me this go around!
Add an else if clause that tests to see if the isStudent variable is true. If it is then open an alert dialog with the message 'Welcome student'.
Can someone please help me out. I have already rewatched the video AND written the code in the workspace for reference. ??? Help!
var isAdmin = false;
var isStudent = true;
if (isStudent) {
alert('Welcome student')
}
<!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
Tobias Helmrich
31,603 PointsHey,
the problem is that you're replacing the existing if
clause but instead you have to add an else if
clause for the students like so:
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator')
} else if ( isStudent ) {
alert('Welcome student')
}
I hope that helps! :)
Jennifer Nordell
Treehouse TeacherYou weren't meant to change the administrator part. You're simply adding a part to say what happens if it's a student that's looking at this. Here... take a look at this code.
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator')
} else if (isStudent) {
alert('Welcome student')
}
Nicollette Whitfield
4,526 PointsThank yuu.....again! :)
Daniel Gauthier
15,000 PointsHey again Nicollette,
Your last attempt was inspired, but you were overthinking it.
Checking out this working code:
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator')
} else if(isStudent === true) {
alert("Welcome student");
}
The takeaway from this particular challenge is just knowing how to include an else if as an additional condition.
It'll get a lot easier the more you work with it.
Good luck!
Nicollette Whitfield
4,526 PointsThank you! I think I am just tired and need a mental break!