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

james mchugh
james mchugh
6,234 Points

Tried this one a dozen ways!

Keeps saying task 1 doesn't work once i change the code, or it says I didn't call lastName toUpperCase. Once I call lastName.toUpperCase it says task 1 not working, which is giving me a migraine headache!

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

var userName
var userName = id.toUpperCase();

var lastName.toUpperCase();
alert ("userName" + "#" + "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>

1 Answer

Neil McPartlin
Neil McPartlin
14,662 Points

Hi James. OK. Take 2 Panadol for that headache, then together we'll make this 13th time lucky :)

Challenge 1: You did pass this one, but one slight mistake is that you declared 'userName' a second time. They just expected you to complete the line they had started. So remove that lonely 'var userName'. So this challenge starts with 3 lines of code and finishes with 3 lines of code as all you needed to do was to complete the 3rd line.

Challenge 2: This states "Finally, add a # symbol and lastName in uppercase to the end of the userName string. The final value of userName is "23188XTR#SMITH"."

So what can we deduce from this?

  • They actually want you to add even more code to that 3rd line only. When the challenge is finished, there are still only 3 lines of code.
  • You will need to use concatenation and you have shown you know how to do this.

So just adding the # symbol gets you to...

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

You already knew how to make something upperCase so we therefore know...

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

...where X refers to the unused declaration in one of the first 2 lines. I'll leave you to finish this off. Slam dunk?

james mchugh
james mchugh
6,234 Points

Ah I see, that makes sense. I don't think I even thought about doing it on the same line, because I thought part 1 wouldn't run. Thanks Neil i'll give it a shot. My headache is gone now, so it should be much easier to think.

james mchugh
james mchugh
6,234 Points

Neil, I got it. It took 3 try's, because for some reason I was putting single quotes around the lastName.toUpperCase, once I removed them and added the + I was missing it passed. Thanks again.

Neil McPartlin
Neil McPartlin
14,662 Points

James. My pleasure. This may not seem intuitive to you right now but keep plugging away at this and soon it will become second nature.