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

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?

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

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
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:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase

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.