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

I really don't get the answer to this task! -Assign an all uppercase version of the id variable to the userName variable

How can you do so? Add an all uppercase version of a var to another var?

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

andren
andren
28,558 Points

You can get the uppercase version of a string by using the toUpperCase() method on the variable, this method was explained and demonstrated in the video directly preceding the challenge.

As far as setting one variable equal to another that is done in the same way you normally assign a value to a variable, like this:

var userName = id.toUpperCase();

Thanks Andren! I had a momentary brainfart and couldn't get it right, but it's solved now :)

Ralph Simon
seal-mask
.a{fill-rule:evenodd;}techdegree
Ralph Simon
Front End Web Development Techdegree Student 30,103 Points

Hi Ana,

When you fail a challenge it will usually give you a 'hint' on what you could do to pass it. In your case the hint is to use the string method 'toUpperCase()' (don't forget the parentheses at the end).

Transforming a string to uppercase

The first part of this particular challenge asks you to transform a string to uppercase. That string is stored in a variable called id:

var id = "23188xtr";

If you'd like to transform a string to all uppercase characters, you call the toUpperCase() method on it which could be done in the following ways:

var id = "23188xtr";
id.toUpperCase(); // ==> resulting value: "23188XTR"

// since the variable id is equal to a string you can call string methods on it (there's a link to the documentation below);

All you have to do now is assign that result to a new variable called userName:

var userName = id.toUpperCase(); // ==> resulting value of userName: "23188XTR"

Remember that variables are containers that reference a value. So now id holds the lowercase value of "23188xtr" and userName holds the uppercase value of "23188XTR". Since they reference strings, you can call string methods on them like I just showed you.

If you'd like to know more about the toUpperCase() method, here's a link: toUpperCase() on devdocs.io.

I hope this helps. If you're still stuck, be sure to rewatch the video right before this challenge: Working with Strings and Finding Help

N.B. Devdocs.io simply refers to the documentation you'll find on Mozilla, but it comes in very handy when you need to know something specific quickly. It also has documentation for languages, frameworks and development environments that are not covered on Mozilla. It really is resource worth bookmarking!