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

Daniel Glennie
Daniel Glennie
42,854 Points

Why won't this concatenation work? I have tried += and x + y + z formatting.

I have created a variable called userName and assigned the output of toUpperCase(id). I have tried to add the # and SMITH like this

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

and like this var userName = String.prototype.toUpperCase(id); userName += "#"; userName += String.prototype.toUpperCase(lastName);

What am I missing?

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

var userName = String.prototype.toUpperCase(id);
userName += "#"; 
userName =+ String.prototype.toUpperCase(lastName);
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="app.js"></script>

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there! In your last line, you have the + and equals signs backwards. It should be +=. But even if I change that, the challenge still fails. You ned to run the toUpperCase method directly on the string in question.

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

Hope this helps! :sparkles:

edited for accuracy and additional information

Here's the MDN documentation:


Daniel Glennie
Daniel Glennie
42,854 Points

Thank you! I noticed the += was the wrong way round right as soon as I posted the question but that didn't fix the problem. It seemed as if the final value assigned to userName was just "#" but I can't think why that would be.