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 trialJeffy evans
3,305 PointsHaving trouble with challenge 2 of 2 in Stage 2 section=Storing and Tracking Information with Variables
What's the answer? Challenge Task 2 of 2
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".
var id = "23188xtr";
var lastName = "Smith";
var userName
<!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>
Jeffy evans
3,305 PointsThanks Thomas and Damien! I was simply over-killing my answer. :)
1 Answer
thomasthackery
12,224 PointsComplete 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".
- When seeing the word "adding," think concatenation, e.g.
var1 + "#" + var2;
Concatenation is like building a sandwich, you can add whatever you want to it using the concatenation operator + to make your String sandwich, if you will. E.g.var mySandwich = "ryebread" + "butter" + "lettuce" + "Jarlsberg" + "herring" + "egg";
- It also says to make an "uppercase version." We need to use a method to achieve this and luckily this language comes with one built in for the String class, e.g.
var1.toUpperCase() + "#" + var2.toUpperCase();
Put all together, your solution would be something like this:
var id = "23188xtr";
var lastName = "Smith";
var userName = id.toUpperCase() + "#" + lastName.toUpperCase();
console.log(userName);
You could also wait, and apply the toUpperCase()
method when you use the variable userName e.g.
var userName = id + "#" + lastName;
console.log( userName.toUpperCase() );
Damien Watson
27,419 PointsDamien Watson
27,419 PointsHi Jeffy, what have you tried? Can you show us some code?