JavaScript JavaScript Basics Storing and Tracking Information with Variables Using String Methods

Finally, add a # symbol and lastName in uppercase to the end of the userName string. The final value of userName is "231

im lost

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

 var userName= "string"
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

Ryan Dudley
Ryan Dudley
Treehouse Project Reviewer

Hello Langelihle Chimanya! Hopefully I can help clear this up and get you on your way.

Currently, you are setting the userName variable to a string literal that holds the value of "string". However, the challenge wants you to use the toUpperCase() method on the id variable, and store that information in userName.

Step 1: Use the JavaScript .toUpperCase( ) string method to assign an all uppercase version of the id variable to the userName variable. We can accomplish this like so:

var userName = id.toUpperCase(); // userName now holds the value of '23188XTR'

The toUpperCase() method is saying, convert the string contained within id to all uppercase and store the resulting string in the userName variable.

Step 2: Finally, add a # symbol and lastName in uppercase to the end of the userName string. The final value of userName is "23188XTR#SMITH". There are a few different ways you could combine these strings, in this example I will just use the += and + operators to concatenate the desired strings to the end of the userName variable like so:

userName += '#' + lastName.toUpperCase(); // userName now holds the desired '23188XTR#SMITH' string.

In the above example, the += operator is saying add # + lastName.toUpperCase() to the value already contained within our userName variable. This means that the userName variable now holds the desired string of 23188XTR#SMITH

I hope this was able to help you out, and if you are still unclear on how this works or need additional help do not hesitate to ask!