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) Making Decisions with Conditional Statements Introducing Conditional Statements

Why 'RUBY' and not 'Ruby'?

Why, when we make a string .toUpperCase, do we have to make the answer all upper-case as in 'RUBY'? Is there a string property that could simply make the first letter of the string capitalized and the rest lower-case so that it could be 'Ruby'?

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

There isn't a method (note: these are methods, not properties) to change to title case, as you suggest, but toUpperCase() works perfectly well for this. You could also use toLowerCase() and test against ruby. If you really wanted to, you could even use the toLowerCase() method, and then toUpperCase() on the first character of the string using the substring() method in order to get Ruby.

We're just testing equivalence, though - it doesn't need to look nice, necessarily. The point is to standardize the input so you can properly test against it. It doesn't have to be any specific capitalization, just so long as you're consistent with what you're testing against.

Kirby Abogaa
Kirby Abogaa
3,058 Points

because we only want to make sure that the input is the same as the answer we are expecting...

so that even if the user input has uppercase or lowercase all over it,

example: Ruby or rUby or ruBy or RuBy.....

the .toUpperCase() function will convert the input to all uppercase before it is compared against a value also set to all uppercase..