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) Storing and Tracking Information with Variables Using String Methods

Andrew Shumway
Andrew Shumway
3,848 Points

The 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());
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="app.js"></script>
Aaron Martone
Aaron Martone
3,290 Points

What 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.

1 Answer

Andrew, 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();