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

Austin Cumberlander
Austin Cumberlander
13,997 Points

Trouble with concatenation in Java Basics

I'm a bit lost in understanding what needs to be done here. Could some one give me a helping hand?

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

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

2 Answers

Martin Balon
Martin Balon
43,651 Points

Hi Austin, you almost had it - just two small mistakes - first, don't pass # as an argument to function toUpperCase() and second, when concatenating two sentences on line 5 you have to use += operator. This is the code that works:

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

var userName = id.toUpperCase();
userName += '#' + lastName.toUpperCase();
andren
andren
28,558 Points

You are quite close, the issue is that in the last line you add the right things together but you don't store the result anywhere, you have to actually store the combined string back in the username variable. This can be done like this:

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

But it can also be shortened by using the += operator which shortens the above to this:

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

You can also combine your last two lines together like this:

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

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

Do note as well that I removed the "#" from your toUpperCase call, that won't cause any issues but is also not actually doing anything useful.

Also as an aside do not use Java as an abbreviation for JavaScript, Java is its own language that has nothing to do with JavaScript, so using that as an abbreviation is bound to cause confusion.