Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


It seems that the code does not check input like "tr" or "tree" which has more than 1 letter

As described in the title, it seems that the code does not check input like "tr" or "tree" which has more than 1 letter. So we assume these cases are legal and just check the first character?

1 Answer

28,521 Points

Your question is not attached to a particular video or challenge, but if you are asking about the Hangman game in the Java Objects course then the answer is yes, your conclusion is correct.

On this line:

char guess = guessInput.charAt(0);

You are pulling out the first letter of the guessInput string, which is the string that contains the guess that was entered. So regardless of how many letters are entered only the first one will be treated as the guess.