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

Tim Cope
Tim Cope
2,280 Points

I tried it like this: var userName = id.toUpperCase() + "#" +lastName.toUpperCase(); Im not sure how else to do it

The problem says to take the var userName = id.toUpperCase(); and add on a # as well as an all caps version of the lastName variable.

app.js
var id = "23188xtr";
var lastName = "Smith";

var userName = id.toUpperCase();
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="app.js"></script>
</body>
</html>
Andrew Liu
Andrew Liu
2,357 Points

Your proposed solution looks okay to me, and it works in this JSFiddle. Another way would be:

userName += '#' + lastName.toUpperCase();

What error are you getting exactly?

Andrew Liu
Andrew Liu
2,357 Points

I just did the Challenge you are asking about and it worked using your proposed answer.

4 Answers

Akhter Rasool
Akhter Rasool
8,597 Points

The syntax which you used is correct.

It seems the expected output is "23188XTR SMITH"

you can try in the following manner:

(variable) userName (equals) id(dot)toUpperCase()+" "+lastName(dot)toUpperCase();

Tim Cope
Tim Cope
2,280 Points

Thanks guys. I think where I was screwing up was I was thinking that once I tried to store id.toUpperCase in username that once I called username again it wouldnt be all Caps. I think something in the video mentioned that it would only change it in that instance but once you called it again without .toUpperCase it would go back to normal. I may have misunderstood.

Andrew Liu
Andrew Liu
2,357 Points

After you call

    var userName = id.toUpperCase();

userName has the upper-case version of id, and if you call userName after this, it should still have the upper-case version of id.

id, however, still has the original, non-upper-case string.

There's no reason for userName to revert back to the original, non-upper-case string.

Perhaps what you mean to say is that toUpperCase() returns an upper-case version of the string, but it does not change the original string.

Tim Cope
Tim Cope
2,280 Points

Yes thats it. Thanks for your patience and help. Still learning and hope to be an awesome developer in the future. You are awesome!

Andrew Liu
Andrew Liu
2,357 Points

You're welcome, and good luck!

Hey Tim,

Yes, in concurring with Andrew, due to the .toUpperCass() already being applied to var id userName has what you need.

Your concatenation would simply be something like this: document.write(userName + "#" + lastName); if you needed spaces, lol ;-) : document.write(userName + " # " + lastName);