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 Working with Strings and Finding Help

how will I use the .length and .toUpperCase() in one line of code?

I use this syntex : document.write((playerName.toUpperCase()).length) It gave me only length.

I know we can use one line to upper case and another line to count the alphabets. But I need to use one line to do it?

What is it you're trying to accomplish? In the video, I don't see Dave trying to use both of those together.

No, he didnt mentioned it on the video but I just wanted to know. How ever I tried with various techniques. I used this; document.write((playerName.toUpperCase())+(playerName.length));

And it gave me all Caps alphabets and also returned with counting the alphabets.

2 Answers

Yes, if your goal is to get both the upper-cased string and the length then you have to do it separately as you discovered.

Probably there is already a response and I am late but to me is not complete so I'll give my response in case someone else is wondering about what is happening here.

What you tried to do is correct but it just does not work the way you thought, here is why,

What you did was to take the string in playerName and make every character to uppercase, then from that same string which is NOW in upper case, you take the length which is the same as the string in lowercase. REMEMBER that you are requesting the string lenght BUT, the string lenght of the uppercase string which is the same lenght as the lowercase one.

So what you did was: lowercase string -> LOWERCASE STRING (now in uppercase) -> length