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

Aaron Sargent
Aaron Sargent
1,441 Points

Aaron Sargent JavaScript Basics Challenge Task 2 of 2

Hi Everyone,

Challenge Task 2 of 2 Finally, add a # symbol and lastName in uppercase to the end of the userName string. The final value of userName is "23188XTR#SMITH".

Trying to do the above challenge and i could use a bit of advice please?

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>

8 Answers

Hiya,

You need to add two things to the userName string. One is a hash symbol and the other is the upper case lastName. Both can be added with the plus symbol - it's called concatenation.

So, what you've got is two additions to be made; first, the hash sign, then the other variable. Let's start with the hash symbol.

userName + "#"

Then we want to put the upper case version of lastName after that. The question says, The final value of userName is "23188XTR#SMITH". So we can do another addition and call the toUpperCase() method on the lastName variable:

userName + "#" + lastName.toUpperCase();

Now, that's all fine but what we haven't done is "saved" it. We've created a new string which will look as it needs to but it isn't stored in userName. We want to assign the new long string back into userName so that the changes are stored. We can do that by starting with userName =. This all looks like:

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

So, the new string we've created is now stored back into the same variable we started with, overwriting the previous value.

Does that make sense?

Steve.

Hi Aaron,

For the second task, take userName and add a # to it using +, then add the lastName (uppercased) to that. Assign that back into userName.

I hope that helps - shout if not.

Steve.

Thanks for the code.

OK - so you've assigned the uppercase id into userName. Now, you want to add two things to the end of userName. First, add a hash symbol. Then add the lastName.toUpperCase() as you have done. Then make sure you assign that back into userName to make the change work.

So:

userName = userName + // the two things here

Make sense?

Steve.

You typod toUpperCase() - it needs a capital 'C'. The rest is fine.

Steve.

Aaron Sargent
Aaron Sargent
1,441 Points

Thanks Steve. For some reason that wasn't going in. Sorry to be a pest. Hope you have a nice evening

Always happy to help! Glad you got it sorted. :+1:

Steve.

Aaron Sargent
Aaron Sargent
1,441 Points

Hi Steve,

Thanks for getting back to me,

I tried the above as mentioned and i keep getting a message stating question 1 is now wrong?

Hi Aaron,

Can you paste your code into here, please?

Steve.

Aaron Sargent
Aaron Sargent
1,441 Points

Hi Steve,

Its probably really simple, i think i might be having a blonde moment lol,

var id = "23188xtr";
var lastName = "Smith";

var userName = id.toUpperCase();
userName + lastName.toUpperCase();

Thanks Aaron

Aaron Sargent
Aaron Sargent
1,441 Points

Hi Steve,

Sorry im still not getting it. The previous video doesn't really explain this very well

Aaron Sargent
Aaron Sargent
1,441 Points

That makes sense thanks, however i am still getting an error?

This is what i have inputted?

var id = "23188xtr";
var lastName = "Smith";

var userName = id.toUppercase();
userName = userName + "#" + lastName.toUpperCase();

Thanks Aaron