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

Tarzine Jackson
Tarzine Jackson
1,023 Points

Why is this "userName += "#" + lastName;" wrong?

I verified the following code in a browser without error.

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

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

So why is this wrong?

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

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

Matthew Rigdon
Matthew Rigdon
8,223 Points

Your code does work in the browser. I believe the error is a result of part 1 of 2 failing based on your code. Part 1 wants you to save id in uppercase. In your current code, you uppercase everything at the end, but by doing that, you are failing part 1.

How I did this:

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

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

Also, your code seems overly complex for the situation.

Tantalizea Lacaden
Tantalizea Lacaden
1,890 Points

I was stuck on this quiz also. My code was the same as yours and it didn't go through. I also tried other ways that I might have missed, such as another parentheses at the end. I don't understand why it's not working!

Matthew Rigdon
Matthew Rigdon
8,223 Points

Tantalizea Lacaden Your answer was the same as mine, or Tarzine's?

Tarzine Jackson
Tarzine Jackson
1,023 Points

Although my answer was correct, it was a little long winded. So here is the break down.

//explain what was done. Concatenate the variable to the "toUpperCase()" method.

//Example 23188XTR = id + . + toUpperCase() id.toUpperCase() //Example SMITH = lastName + . + toUpperCase() lastName.toUpperCase();

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

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

Does that make since?

Tantalizea Lacaden
Tantalizea Lacaden
1,890 Points

Tarzine, were you explaining it to me? I do understand it and had the same answer as above. I'm not sure why it isn't taking my answer though. I guess I'll have to start a new thread.