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 trialAndrew Alvarez
11,964 Pointselse if
Challenge Task 1 of 1
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'.
Bummer! There was an error with your code: ReferenceError: Can't find variable: isSudent
var isAdmin = false;
var isStudent = true;
else if ( isSudent ) {
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>
4 Answers
Frederico Graciano
Courses Plus Student 2,768 PointsLike jacob said you need to have a if statement to use the else if.
and inside the else if argument it's misspelled isSudent seemissing the T there.
When you start the challenge the if statement it's already there so you just need to do the else if statement.
this is how you do it:
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator')
}
else if (isStudent) {
alert('Welcome student')
}
jacobproffer
24,604 PointsHey Andrew,
You misspelled the variable 'isStudent.'
You also appear to be missing your if statement. In order to use an else if or else statement, you'll first need an if statement. Lastly, you'll need to test whether or not the isStudent variable returns true.
Take a look:
var isAdmin = false;
var isStudent = true;
if ( isAdmin ) {
alert('Welcome administrator')
} else if (isStudent) {
alert('Welcome student');
}
Best,
Jacob
Suleiman Leadbitter
15,805 PointsI'm doing everything correctly here and even checked this thread which is the same as I am doing and to top it all the alert box is even showing up but Treehouse is saying it's incorrect :(
Any idea where I go from here? :/
Suleiman Leadbitter
15,805 PointsOk, it was a lower case 'S' in student that was needed :/
Edgar Barrios
Courses Plus Student 7,061 Pointsmy correct answer was
if ( isAdmin ) { alert ('Welcome administrator') }
else if (isStudent) {
alert ('Welcome student')
}
else { alert( 'Who are you?') }