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 Programming Multiple Outcomes

Steve Liu
Steve Liu
2,438 Points

Else if challenge task 1

I currently have the below code but I keep getting an error "Hmm. I don't see the message 'Welcome student' in the alert message." even though the 'Welcome Student' alert pop-up appears.

Can someone please help?

var isAdmin = false; var isStudent = true;

if ( isAdmin ) { alert('Welcome administrator'); } else if (isStudent){ alert('Welcome Student'); }

If you could post the question that might help. Are you sure you want an else if here? Cause you are correct that the popup is happening as expected w/ isAdmin = false and isStudent = true. This would work with just else{alert("Welcome Student")}. Also sometimes even if you miss an exclamation point or add a space in a string it can mess up the challenge.

var isAdmin = false; 
var isStudent = true;

if ( isAdmin ) { 
alert('Welcome administrator'); 
} else if (isStudent){
 alert('Welcome Student'); 
}

3 Answers

I think if you use lower case S for student in the alert...it will pass.

//you have
if ( isAdmin ) { alert('Welcome administrator'); } else if (isStudent){ alert('Welcome Student'); }
// I think this will pass...Welcome student not Welcome Student
if ( isAdmin ) { alert('Welcome administrator'); } else if (isStudent){ alert('Welcome student'); }
Mauro Teixeira
Mauro Teixeira
3,727 Points

This shouldn't have any impact.

Mauro Teixeira
Mauro Teixeira
3,727 Points

I Steve, if you could re-write your question it would be good, right now is a little hard to understand your issue.

You currently have two variables. isAdmin (set to false) and isStudent (set to true).

The "if... else if" clause you are using will first evaluate the isAdmin variable and, if it is true, will popup the alert "Welcome administrator". However, your isAdmin variable is not true, so the "if" will fail and will fallback to the "else if", which in turn will evaluate the isStudent variable. If this is true (which it is), it will show a popup saying "Welcome Student".

Is your code doing this? If so, then everything is correct.

Also, notice that if you put isAdmin and isStudent both set to true, you will only see the message "Welcome administrator", because since the first if will pass, it won't even evaluate the else if.

I know that in real world stuff something like grammar in an alert won't matter. However, I have found that in the code challenges if they say to use alert("Zebra").. then alert('zebra')... wont pass

Mauro Teixeira
Mauro Teixeira
3,727 Points

I didn't realize that's what you meant. Sorry john.

Alexander Alegre
Alexander Alegre
14,340 Points

Hello Steve, there are no sytax errors with your code. It could just be a browser glitch. I pasted your code into Brackets and ran it on Chrome without any modifications and it displayed the correct message. Try using a different browser?

Good luck!