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

Tine Jakomini
Tine Jakomini
2,494 Points

I did not understand the previous video so I can't complete this task. An explanation would be apreciated.

Plese help.

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

var userName  = "";
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>

2 Answers

Bob Swaney
Bob Swaney
13,010 Points

the 1st part of the challenge asks you to use the toUpperCase() String method to store an uppercase version of the ID into the username variable...so:

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

var userName = id.toUpperCase();

Because id is a string, it inherits the methods that the String object has...so any of the methods that work on a string will work on the id variable...It's asking you to then take the uppercase version and store it into a new variable..username (which it provided)...

The 2nd part of the challenge asks you to add a # in between an uppercase version of the lastName variable and store it back into the userName variable.. it wants you to concat this together...:

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

you have to add quotes around the # to turn it to at string, concatenated with the lastName variable with the toUpperCase() method...hope this explanation helped!! If you have any other questions, don't be afraid to ask!

Happy Coding!

Tine Jakomini
Tine Jakomini
2,494 Points

TY Bob it really helpt.

Tine

Bob Swaney
Bob Swaney
13,010 Points

after reviewing the video to understand what you are learning, the second part of the challenge could be coded like it was in the video,

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

the userName variable doesn't have to be used again...the += operator will take whats on the left side, add to it, and automatically bind it back to userName...both answers work, this one is just a little bit shorter and more conventional..the first example shows you a little bit better of what is going on.
Just remember that whatever is contained in a variable is still the type of object it was...almost like a placeholder...so what ever you and do to that type of object, you can do to the variable holding that object! Keep working at it!

Bob Swaney
Bob Swaney
13,010 Points

last thing...lol if you found my answer helpful, please don't forget to upvote it, that really helps me as well ;)