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

David Michael Bryant
David Michael Bryant
5,068 Points

Concatenation conundrum.

If someone could clarify what I'm missing I'd be grateful! Thanks!

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

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

3 Answers

Christopher De Lette
PLUS
Christopher De Lette
Courses Plus Student 7,139 Points

Hi David,

To concat variables for this challenge you can try the following method:

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

var username = id.toUpperCase() + '#' + lastName.toUpperCase();

hope this helps

Take care and happy coding!

David Michael Bryant
David Michael Bryant
5,068 Points

I managed to get it and that was indeed the solution. Thank you for the quick response!

Steven Parker
Steven Parker
231,007 Points

You were really close! What you have there is fine except for just one thing: you can only declare a variable one time.

So just remove the "var" from the last line and you'll have it.

David Michael Bryant
David Michael Bryant
5,068 Points

I tried that as well, and it was apparently looking for it to be all on one line. In your suggestion, it told me that question 1 was now incorrect. I'm guessing because it replaced the variable altogether right? JS lets us get away with not putting var and it still creates the new variable doesn't it?

Steven Parker
Steven Parker
231,007 Points

You already declared the variable on the previous line, so this would not be a case of implicit declaration. By removing the "var" from the second line it becomes an ordinary assignment, which can be done any number of times in the life of a variable.

David Michael Bryant
David Michael Bryant
5,068 Points

Guess it just really wanted that one liner. Badum bum. Chhh

Thanks!

Steven Parker
Steven Parker
231,007 Points

It works either way. After removing that last "var" your original code passes also.