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

String Concatenation

I know how to concatenate but this question is confusing and I don't know where I went wrong. Please help.

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

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

4 Answers

huckleberry
huckleberry
14,636 Points

as William Li pointed out, your problem there is a syntax error... the extra semicolon after the <code>var userName = id.toUpperCase()</code> part of the whole thing

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

//Riiiiiiiiiiiiiiiiiight there^

And I think you made the mistake because you weren't thinking in terms of building upon your previous code and instead you were just trying to make it all work in one fell swoop of an assignment lol.

Take a look at the exercise again. The exercises is in two steps.

In the first step you're to assign an all upper case version of <code>id</code> to the <code>userName</code> variable.

So your first bit of code should have been this...

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

var userName = id.toUpperCase(); 

All well and good.

But now the 2nd part wants you to add the # symbol and an all uppercase version of the <code>lastName</code> variable.

What you have is slightly "extra" then you need. You already assigned <code>id.toUpperCase();</code> to the <code>userName</code> variable... so all you need to do NOW is add the additional stuff they asked for TO that variable.

I'm not sure what operators have been covered in the course up until this point but there are two ways to do this. One verbose, one not so verbose lol.

//your code so far after the first stage of the exercise

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

var userName = id.toUpperCase(); 

/*NOW add an all upper case version of lastName to the userName and put a # inbetween them. 
Ok, well... we already know that userName has a value of id.toUpperCase() so we can now just add 
the  other stuff TO that new variable we just got done creating. */

//verbose method

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

//cleaner method

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

/*the += operator will add whatever's on the right hand side of the += TO the value of what's on the left 
hand side of the += operator. += is just variable slang for "yo, interpreter! you see dis right here? Eh?
Yeah.... gonna need you to be a good little interpreter and append everything after this to me myself here...
capiche?"*/

Hope that helped!

Cheers,

Huck - :sunglasses:

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hello, dianaduong

Your code has an extra semicolon ; after id.toUpperCase(), remove it and you're good to go.

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

Question: 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".

It's always the semi colon's fault! Thanks for your response William and Huck.

Huck - I appreciate the time you took to write this out for me. Very helpful! I definitely like the cleaner method. Thank you!