Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Using String Methods

Elena Paraschiv
Elena Paraschiv
9,938 Points

Using String Methods challange_code

Complete the assignment to the userName variable by adding a # symbol followed by an all uppercase version of the lastName variable. In other words, using string concatenation so that the final value of userName is "23188XTR#SMITH". Did someone manage to fix this?

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

var userName = id.toUpperCase(); 
userName = lastName.toUpperCase();
username = "id" + "#" + "lastName";
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

Hi Elena,

There are a number of ways to solve this challenge, but the most important concept to take away is that when doing operations with variables, such as concatenation with strings, you do not put those variable names inside of quotes. You just put the variable name itself.

Also, you have to think about what the end result is. The string should be upper case id, a # sign, and then upper case last name. With the way you have it right now, it starts out as upper case id. Then, it is overwritten and becomes only upper cast last name. Then, it is overwritten a 2nd time and becomes a string that says "id#lastName". It needs to have the values contained within id and lastName. In order to do that, you just use the variable name as I mentioned above.

The simplest method to solve this is to just add the "#" after putting id to upper case and then add last name to upper case.

var id = "23188xtr";
var lastName = "Smith";
//put the upper case version of id plus a # plus last name to upper case
var userName = id.toUpperCase() + "#" + lastName.toUpperCase(); 
Elena Paraschiv
Elena Paraschiv
9,938 Points

Thanks Marcus. That was very helpful!

You're welcome, Elena. Do you have any more questions? Don't hesitate to ask because I will help you to the best of my ability. =]

Elena Paraschiv
Elena Paraschiv
9,938 Points

Thanks a lot! Now I am good

Awesome blossom! Happy Coding! =]