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 trialJustin Townsend
4,720 PointsElse if statment
I am not really sure what to do here!
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator');
} else {
}
if(isStudent === true){
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>
2 Answers
jamesjones21
9,260 PointsHi Justin, you are almost there just need to do amend the syntax for the else condition, as it checks against the variable isAdmin, and as a single condition it will check if true / false, so if the isAdmin is false it will go to the else statement and alert 'Welcome student'
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator');
} else {
alert('Welcome student');
}
but using an else if condition would look like this:
as with else if they also need open and closing parenthesis to include the condition you want to test against.
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator');
} else if(isStudent){
alert('Welcome student');
}
hope this helps :)
Justin Townsend
4,720 PointsThanks James this really helped!