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

Shilpa K
Shilpa K
12,722 Points

Complete the assignment to the userName variable by adding a # symbol followed by an all uppercase version of the lastNa

Complete the assignment to the userName variable by adding a # symbol followed by an all uppercase version of the lastName variable. In other words, using string concatenation so that the final value of userName is "23188XTR#SMITH".

I am not sure what I'm doing wrong here, could someone help me with this code challenge?

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

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

This is the code I wrote and it works but it is not what the instructions requited.

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

var userName = id;

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

just saying!

20 Answers

It says... "Complete the assignment to the userName variable" so you have to add things to that variable instead of a new line.

var userName = id.toUpperCase()+ "#" + lastName.toUpperCase();
Shilpa K
Shilpa K
12,722 Points

Ah, thank you!

You are welcome. As the instructor said below if you want to assign it to username. The other way round is to do it this way

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

this is a 2nd correct solution to it.

Markus Moench - I do not think it is wrong, at least not for the time it was written at. Since this is an old question though there could be changes in the curriculum or maybe something wrong with your code.

I also dont know where the # came from.

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

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

NOTE: only from task 2 of 2

what does the # stand for?

Joe Williams
Joe Williams
4,014 Points

I was also able to do this and got a correct answer:

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

Joe, You are correct. THANKS!

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

HI Shilpa K

You need to assign an uppercase version of the id variable, plus a # symbol plus an uppercase version of the lastName variable to the userName variable.

This line of code

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

doesn't assign a value to userName -- you need an equals sign to assign a value to a variable.

Cora Weiss
Cora Weiss
Courses Plus Student 1,271 Points

my correct answer did not incluse the # symbol

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

Kleovrotos Tsimperis
Kleovrotos Tsimperis
Courses Plus Student 13,831 Points

Dave, why does the code userName += id.toUpperCase() + "#" + lastName.toUpperCase(); needs the "#" element to be correct? It doesn't mention at any point that the hashtag should be part of the string userName??

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi Kleovrotos Tsimperis

The instructions for the second part of the challenge state: "Finally, add a # symbol and lastName in uppercase to the end of the userName string. The final value of userName is "23188XTR#SMITH"."

jiwan gurung
jiwan gurung
4,248 Points

why do u need to ad a hashtag?

Task one:

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

var userName = id.toUpperCase();

Task two:

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

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

Paul Taylor
Paul Taylor
9,914 Points

That was grossly confusing....So to clarify is '' the same as ""? Because that's why it wouldn't allow me to pass.

After several failed attemps and several instances of me screaming at my computer, I decided I had enough of the code challenge being full on retarded, so I did the code until the point where it said it was "23188xtr#smith" and not "23188XTR#SMITH" so I manually went into the code and changed the ID variable from 23188xtr to 23188XTR and I changed the lastName variable from "smith" to "SMITH", and then it finally decided that it wanted to work.

I know I probably cheated the system but I was tired of it being stubborn with me when I know I was using the right code.

Markus Mönch
Markus Mönch
16,383 Points

It is a very bad platform if u do the right thing but it says it is wrong.

This worked for me

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

After SEVERAL attempts on this exercise, this worked! In the TTH program, I think it is getting "hung up" on the variable userName and in turn making this exercise extra challenging. It should not be this difficult!

var userName = "23188XTR#" + lastName.toUpperCase()

this worked for me

Markus Mönch
Markus Mönch
16,383 Points

that works but it should not work like that.,

Markus Mönch
Markus Mönch
16,383 Points

why is no instructor here clarifying clearly what the problem is here? I write what the moderator posted

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

and it doesnt work

it says you only need to call 'toUpperCase()' on 'id' and 'lastName'

Markus Mönch
Markus Mönch
16,383 Points

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

also doesnt work

Dave McFarland
Dave McFarland
Treehouse Teacher

Markus Moench what error are you seeing when you type this?

Andres Ramirez
Andres Ramirez
18,094 Points

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

var userName = id.toUpperCase();

Tobia Crivellari
Tobia Crivellari
14,331 Points

Hi!

I've tried this line of code for this challenge:

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

Could you explain me why is not working? I can't figured out...

Thank you!

Tobia.

Jordan King
Jordan King
1,286 Points

Hi Tobia, I had a annoying time with this question, but managed to figure it out. I simply wasn't remove the ; after the first part id.toUpperCase(); The reason why yours isn't working is because you have done += from what I know its adding userName = userName

it should be

userName = id.toUpperCase () + '#' + lastName.toUpperCase ();

Juan Aviles
Juan Aviles
12,795 Points

I'm having problems with this as well. I understand the solutions above, but I'm curious to know why you can't use concatenation to create the string, then toUpperCase on the entire string like this:

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

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

I get this result when I try to enter it: Bummer! Did you add the '#' character between id and lastName?

Up until this point of this track, I've had very few times where I've been stuck but this one got me hard. I went through the community forums after countless trial and error only to find other with the same issue. When I finally passed the challenge, I almost felt obligated to come back and put my small bit of help into it.

After going through and trying all other lines of code pasted here and reading other peoples' methods, I kept failing. Task 1) If you set the id.toUpperCase in the console.log() it is accepted. Task 2) Make sure, I mean absolutely sure that your words are capitalized in the correct areas. lastname won't work, make sure the 'N' in lastName is capped. protip: Just set the line of code inside the var userName to keep it a little more simple and stop yourself from getting overwhelmed with the code. (It helped me get it finished correctly and actually retaining a little more than I thought I would.)

Also, this was my solution. Like I said, posting it inside the var userName keeps it simple and still correct. var userName = (id.toUpperCase()) + '#' + (lastName.toUpperCase());

if you follow along the instructor did mention how Concatenation works with strings

Complete the assignment to the userName variable by adding a # symbol followed by an all uppercase version of the lastName variable. In other words, using string concatenation so that the final value of userName is "23188XTR#SMITH".

the code stated ` var id = "23188xtr"; var lastName = "Smith"; var userName = id.toUpperCase(); \` the += is shorthand for combining a value inside a variable with another value.

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

Ivana Lescesen
Ivana Lescesen
19,442 Points

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

After completed the Task 1, I tried userName += "#" + (lastName.toUpperCase()); and userName + "#" + lastName.toUpperCase(); for the second task, but the system keep saying it looks like the Task 1 is no longer passing. Couldn't figure it out what part is wrong.

I answered with :

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

And the site came back saying : Bummer! The userName variable is "23188XTR#SMITH" not "23188XTR#SMITH".

The answers are identical. Am I crazy or is something wrong?

Phong Somlith
Phong Somlith
5,675 Points

Jefferson, I'm having the exact same issue as well. I thought I was going nuts but after verifying, those answers are completely identical as what you stated. I'm still trying to figure this one out...

Jazzy schaeffner
Jazzy schaeffner
2,091 Points

I used this and it was correct!

var userName = id.toUpperCase();

Adriano Gomes
Adriano Gomes
5,468 Points

My answer was var userName = id.toUpperCase(); and it was correct as well.