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

Clint Dehner
Clint Dehner
8,808 Points

Task 2

I'm having issues with bringing the variables together with the # sign Im not sure what I'm doing wrong here...

app.js
var id = "23188xtr";
var lastName = "Smith";
id.toUpperCase();
var userName = 'id'+'#' + 'lastName';
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>
Damien Watson
Damien Watson
27,419 Points

Sorry, first time posting... answer below.

4 Answers

Hello Clint and Damien:

Damien you are correct except, toUpperCase() method doesn't actually modify the variable.

I believe what you are looking to do is something like:

var id = "23188xtr";
var lastName = "Smith";
id.toUpperCase();

var userName = id.toUpperCase() + "#" + lastName.toUpperCase();
Damien Watson
Damien Watson
27,419 Points

Hi Clint,

You have declared the variables in line 1 & 2. If you wrap them in quotes you will get the characters 'id' and 'lastName' instead of what id and lastName are set to.

To join or concatenate variables and text, your username line should read something like:

var userName = id + '#' + lastName;

You would also need to set the lastName to uppercase prior to joining the strings or you could chain it all together, though I haven't done this lesson so I don't know what is recommended.

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

I'm not sure of the exact syntax they are asking for, but if I look at fixing the 'app.js' so that it will run without errors, it should be something like:

var id = "23188xtr";
var lastName = "Smith";
id.toUpperCase();
lastName.toUpperCase();
var userName = id + '#' + lastName;

Sorry, without further understanding of the question this is all I can help.

Clint Dehner
Clint Dehner
8,808 Points

I tried that too ans still won't let me pass the 2nd task.

Damien Watson
Damien Watson
27,419 Points

I have updated my answer above to modify the code you have shown in 'app.js' to remove errors. This is semantically correct, but it depends what the exact question is for what they are expecting.

Clint Dehner
Clint Dehner
8,808 Points

@ Jason that worked good sir, thank you and Damien for the help.