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

I'm typing it exactly how it told me to and is still telling me i'm wrong. Do I need to delet the id.toUpperCase();

It would be great if these quizzes can give clearer explanations why i am wrong. I have typed it the exact way it told me and is still telling me I am wrong.

var id = "23188xtr";
var lastName = "Smith";

var userName = id.toUpperCase();
userName = "# + lastName.toUpperCase()";
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JavaScript Basics</title>
<script src="app.js"></script>
12,662 Points

You are almost correct but take a look at your quotations. The lastName.toUpperCase() returns a string and should not be within the quotes. Also, you cannot perform string concatenation from within a string.

1 Answer

Cheo R
Cheo R
37,145 Points

What you want to end up with is something like


Your code

var userName = id.toUpperCase();
userName = "# + lastName.toUpperCase()";

Is close. You are assigning to userName twice.

In the first instance, you are assigning to userName as stated in the prompt.

In the second, you're overriding what you had before and assigning the string "# + lastName.toUpperCase()" to userName.

The problem with the above, is that you're not getting (as a string) the result of calling lastName.toUpperCase(). You're actually assigning the characters lastName.toUpperCase() to userName. You can get the result of calling lastName.toUpperCase() by either using interpolation with backticks ` `, i.e. lastName.toUpperCase() or you can concatenate the result to the rest of the string.

userName = id.toUpperCase() + "#" + lastName.toUpperCase();

// or 

userName = `${id.toUpperCase()}#${lastName.toUpperCase()}`;

thank you so much!