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

Help with this question I am really struggling

I am really struggling with this question i have tried using MDN for help and I have also re-watched the training video but i still cant work out the answer. I was wondering if I should learn html before trying to learn JavaScript?

app.js
var id = "23188xtr";
var lastName = "Smith";
.
var userName
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>

2 Answers

Dan Collins
Dan Collins
310 Points

What are you trying to do?

Neil McPartlin
Neil McPartlin
14,662 Points

Hi Thomas. Let's look at each challenge in turn.

Challenge 1: Use the JavaScript .toUpperCase( ) string method to assign an all uppercase version of the id variable to the userName variable.

So you see in app.js that they have already declared the variable 'id' and given it a string value of "23188xtr". They have also declared the variable userName but it currently has no value and they are asking you to give it one. The instructions explain that you need to apply the proposed string method to the variable 'id' by completing the userName declaration like so...

Answer 1: var userName = id.toUpperCase( );

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

Answer 2: I could give you the answer but I see you are keen to resolve this yourself so I will give you some pointers.

  • To answer this, you are going to be adding to the answer given in Answer 1 and on the same line.
  • You are going to use 'concatanation' to add both the '#' and the 'SMITH' to Answer 1.
  • To achieve 'SMITH' rather than 'Smith', you will re-use the lesson learnt in Challenge 1.

As for your html query, learning that first would not help here, this is pure JavaScript. Good luck.