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 trialAndrew Shumway
3,848 PointsThe variable is correct and yet...it's not correct?
I am attempting to have the userName variable equal 23188XTR#SMITH apparently that is what my code is putting out. However the error message reads - the 'userName' variable is "23188XTR#SMITH" not "23188XTR#SMITH".
Is the code not written entirely correct?
var id = "23188xtr";
var lastName = "Smith";
var userName = ('id'.toUpperCase());
userName = (id.toUpperCase() + '#' + lastName.toUpperCase());
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<script src="app.js"></script>
</body>
</html>
1 Answer
jcorum
71,830 PointsAndrew, close, but you need to make id upper case, and then use that in the next line:
var id = "23188xtr";
var lastName = "Smith";
var id = id.toUpperCase();
var userName = id + '#' + lastName.toUpperCase();
Aaron Martone
3,290 PointsAaron Martone
3,290 PointsWhat happens is: L1. Stores '23188xtr" into 'id'. L2. Stores 'Smith' into 'lastName'. L4. Stores 'ID' into 'userName'. ('id' is a literal string containing the value 'id', not a variable reference to L1's var. L5. Concatenates '23188XTR' + '#' + 'SMITH' into '23188XTR#SMITH' and overwrites the previous value of 'ID' that was assigned into 'userName' on L4. As an aside ('id'.toUpperCase()); is unnecessary to enclose in parens, as is with L5.