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

Michael Russell
Michael Russell
2,597 Points

Quiz Error

Using string method quiz when asked to concatenate the id, first name and username I got an error saying did you add "#" between id and first name, which I did.

I tried the same code in the workspace app and it printed out the required message successfully.

the code I used was

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

I can't see what I did wrong and considering it worked for me on the workspace app I can only assume there's an error in the quiz?

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

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

It wants the lastName to be uppercase as well:

var userName = id.toUpperCase() + "#" + lastName.toUpperCase();
Michael Russell
Michael Russell
2,597 Points

You're right but actually that didn't seem to be the issue I pasted this again -

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

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

and it works now! Says its correct

I just retook the challenge and John Tasto is correct. You get the cited error if you do not have the .toUpperCase() on lastName. The quiz should not pass without the .toUpperCase().

Michael Russell
Michael Russell
2,597 Points

Hi Ted,

Thanks for the reply. I should have said I hadn't gotten as far as John, I was the question before so it wasn't asking for the lastName to be uppercase at that point but I saw afterwards like you said that in the last part of the question it does ask for that.

Although one thing I did notice, in the videos I thought it said you could use " or ' for strings and originally I had accidentally put '#' does it matter if in previous statements I've used one way of doing it? When I changed that command to "#" it worked

In my experience using single or double quotes does not matter as long as you open and close with the same type.

There are two things to be aware of, though. There are time where you want the quote mark to appear. In that case it does matter: 'If we used this, the ' in it's would act as opening and closing of the quote and you would have errors.' "But if we use double quotes, the ' in it's would appear properly." I think SQL also requires using double quotes, but I am not sure.

There is also an option of forcing characters with . So I think this would display correctly: 'This is another way to display \' in it\'s when you use single quotes around the string.'