Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Using String Methods

Shashaank Srinivasan
Shashaank Srinivasan
2,440 Points

I've inserted the '#' symbol in quotations, what am I missing in the code?

Any help is greatly appreciated.

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

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

5 Answers

Navid Mirzaie Milani
Navid Mirzaie Milani
6,273 Points

@Shashaank Srinivasan what do you want to achieve? because when i just type the code you write in the example i get :

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

result is: id#LASTNAME. So whats going wrong at your?

Rich Donnellan
Rich Donnellan
25,767 Points

You're literally outputting "id" and "lastName". Variables will not work with quotes (single or double); remove them from id and lastName.

The problem as mentioned by Rich is the incorrect use of variables but also missing the task. The task is asking to add a # symbol and an uppercased version of the last name to the uppercase of the id.

// Your solution:
var userName = "id"+"#"+"lastName" .toUpperCase();

Here you aren't using the variables id and lastName but using the strings "id" and "lastName". You want to use those as variables.

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

We have something closer to the solution, but now we're getting only the lastName variable to be in uppercase. To get the whole string to be uppercase we can either uppercase the individual parts or to uppercase the overall string as so:

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

// OR 

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

Since we want to keep things DRY, we probably want to use the first version.

Best,

Charles C. Lee :D

Navid Mirzaie Milani
Navid Mirzaie Milani
6,273 Points

aaah damn .. i didn't even recognise the mistake ... and those were variables my bad indeed and Charles Lee is right :).

Rich Donnellan
Rich Donnellan
25,767 Points

It's also worth mentioning that this question has been asked many, many times. Peruse the JavaScript related forum for any potential clues before posting your own.

Cheers!