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

Java Java Objects (Retired) Delivering the MVP Refactoring

Help

I do understand we need the "return applyGuess" what I don't understand is why we need the "(letters.charAt(0))".

2 Answers

Allan Clark
Allan Clark
10,810 Points

The letters variable represents the input from the user. It is of type String. Because we are accepting the input as a String the user could input "you know nothing John Snow", but are only concerned with the first letter of the String. Strings are 0 indexed so to get the first letter of any String charAt(0).

return applyGuess(letters.charAt(0));
// This gets the first character of the letters variable, 
// 'y' in the above user input 
// sends that character to the applyGuess() method
// and returns the boolean if it was added

Thanks a lot !

Allan Clark
Allan Clark
10,810 Points

Thank me with points bruh bruh ;)