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 trialAkashdeep Matharu
1,719 Pointshow 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.
Jason Anello
Courses Plus Student 94,610 PointsWhat is it you're trying to accomplish? In the video, I don't see Dave trying to use both of those together.
Akashdeep Matharu
1,719 PointsNo, 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
Jason Anello
Courses Plus Student 94,610 PointsYes, if your goal is to get both the upper-cased string and the length then you have to do it separately as you discovered.
aleja
572 PointsProbably 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
Akashdeep Matharu
1,719 PointsAkashdeep Matharu
1,719 PointsI 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?