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

Yohan Aton
Yohan Aton
1,738 Points

Not sure why this isn't working and showing 'Welcome student' in alert message...

var isAdmin = false; var isStudent = true;

if ( isAdmin = true ) { alert('Welcome administrator'); } else if (isStudent = true) { alert('Welcome student'); }

any help or insight would be greatly appreciated. Thanks!

Yohan Aton
Yohan Aton
1,738 Points

Thanks so much - Got it now!

4 Answers

rdaniels
rdaniels
27,258 Points

This code passed in Chrome...

var isAdmin = false;
var isStudent = true;

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

Hope this helped!

Yohan Aton
Yohan Aton
1,738 Points

Thanks for chiming in!!!

Faraz Hasan
Faraz Hasan
4,596 Points

also you can write your code with the black background if you write 3 backticks (```) surrounding it!! I just learnt that the other day....click Markdown Cheatsheet below the answer box to check other syntax examples!!

e.g (without space between backticks - btw backticks on my mac are next to the shift key on the left of the keyboard on same key as ~):

'' ' CODE GOES HERE '' '

Jon-

I just ran it in the Chrome console and it worked and provided the correct alert. Are you using Firefox or a different browser? I was using Firefox when I first started and I often wouldn't get alerts. I've switched over to Chrome for all dev work and have no longer had that issue.

Yohan Aton
Yohan Aton
1,738 Points

Hi Mike - Think I'm going to follow your suggestion. Thank You!!!!

Use 2 equal signs == for comparisons and one equals = for assignments.

Yohan Aton
Yohan Aton
1,738 Points

Yup... somehow missed that... Thank You!!!