Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Error: I don't see the message 'Welcome student' in the alert

This is my code...

var isAdmin = true; var isStudent = false;

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

script.js
var isAdmin = true;
var isStudent = false;

if ( isAdmin === true ) {
    alert('Welcome administrator');
} else if ( isStudent === true ) {
    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>

Take out the "if" in the "else if" statement. There is no need for it and may be causing the issue.

Yes I can refactor that way, but my code is technically valid JS ... I was just wondering why it spit out an error. It was a bug I restarted and this code worked. I have experience with JS but wanted to keep to what was being taught and not jump ahead eg. refactor but yes something like ...

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

would also work

3 Answers

looks like it is <script src="script.js"></script> ... this is a code challenge though and usually treehouse has it already plugged up I never touch the index on these well so far but I double checked and looks like the code challenge before this. I tested this code on browser console also and it works

it was def a bug ... i restarted the challenge from the start and it worked now

David Perkins
David Perkins
9,607 Points

Happy days... kind of ha ha

Glad you got it sorted 👍🏻

yes ...thanks for replying

David Perkins
David Perkins
9,607 Points

Everything checks out from what i can see... are you sure that the script.js file is correctly linked in relation to the index.html file?