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 trialDaniel Nunez
1,536 PointsError: 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'); }
var isAdmin = true;
var isStudent = false;
if ( isAdmin === true ) {
alert('Welcome administrator');
} else if ( isStudent === true ) {
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>
Daniel Nunez
1,536 PointsYes 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
Daniel Nunez
1,536 Pointslooks 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
Daniel Nunez
1,536 Pointsit was def a bug ... i restarted the challenge from the start and it worked now
David Perkins
9,607 PointsHappy days... kind of ha ha
Glad you got it sorted 👍🏻
Daniel Nunez
1,536 Pointsyes ...thanks for replying
David Perkins
9,607 PointsEverything 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?
Aidan Caddle
18,983 PointsAidan Caddle
18,983 PointsTake out the "if" in the "else if" statement. There is no need for it and may be causing the issue.