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

Assign an all uppercase version of the id variable to the userName variable. Don't understand the question.

the exercise is :

var id = "2318"; var lastName = "Smith";

var userName

can't figure it out. Can anyone help!!

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>

4 Answers

So the requirement is this: Assign an all uppercase version of the id variable to the userName variable

Let's break it down step by step:

STEP 1 We need to assign something to the userName variable. So at some point we have to do something like:

var userName = ???

The question remains: what to put after the equals sign? The challenge says it needs to by the uppercase version of the id variable

STEP 2 Transform the id variable to all-uppercase In JavaScript, all string objects have a member method defined on them which you can use to apply the all-uppercase transformation on the string itself (all lower case letters will be replaced by their upper-case counterpart). So what you need in the end is something like:

var userName = id.toUpperCase()

Hope this helps.

Mark VonGyer
Mark VonGyer
21,214 Points

var username= lastName.toUpperCase();

What is the period stands for? Can the id be replaced of lastName instead?

Mark VonGyer
Mark VonGyer
21,214 Points

toUpperCase is a method that can be passed to any string. So you can use id.toUpperCase(); or lastName.toUpperCase();

You need the period to indicate the end of a statement.

Re-reading your question.

var userName = id.toUpperCase();

this is the correct way.

The period is a basic piece of JavaScript syntax that allows for the invocation of a method (or the access of a member property) on a particular object instance. If this notation is not clear for you I would strongly suggest to recap the previous lectures in the JavaScript series.

As far as the second question goes, why would you replace the id with lastName? The requirement is clear: Assign an all uppercase version of the id variable to the userName variable. It makes no reference to the lastName variable.

Thank you very much!! which lecture are you referring?

I looked over the lectures in the JavaBasics course and I don't see any object orientation concepts listed there. I think these concepts are introduced later in the more advanced courses. For now, just take this information as it is.