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

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Add an Else If Clause

else 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

script.js
var isAdmin = false;
var isStudent = true;
else if ( isSudent ) {
    alert('Welcome student')
}
index.html
<!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

Like 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')

}

Hey 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

I'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 :(

Me no wrong!

Any idea where I go from here? :/

Ok, it was a lower case 'S' in student that was needed :/

Edgar Barrios
PLUS
Edgar Barrios
Courses Plus Student 7,061 Points

my correct answer was

if ( isAdmin ) { alert ('Welcome administrator') }

else if (isStudent) {

alert ('Welcome student')

}

else { alert( 'Who are you?') }