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


Steve DeYoung
Steve DeYoung
1,313 Points

Needs clarification on this method (validateGuess)

The rest of the method makes sense but I would like some clarification on this part. How does this check to see if a letter is already guessed?

if (mMisses.indexOf(letter) >= 0 || mHits.indexOf(letter) >= 0){
  throw new IllegalArgumentException(letter + " has already been guessed");

2 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Steve,

the indexOf method returns an integer that represents the index position of a spesific letter inside mMisses or mHits.

If letter havenΒ΄t been guessed yet, the letter is not inside mHits or mMisses (no index position). The indexOf method will return -1 (no index found).

Every returned integer higher or equal then 0 triggers the exception. If the returned integer is 0, then the letter is on the first index inside mHits or mMisses.

Makes sense?


Steve DeYoung
Steve DeYoung
1,313 Points

Ah ok.. Yes makes sense now. Thanks!