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 Creating the MVP Prompting for Guesses

Wojciech Lisowski
Wojciech Lisowski
3,093 Points

i do not understand why at the end of the line is -1. boolean isHit = answer.indexOf(letter)!=-1;

i make program java obejct Scrrable: boolean isHit = answer.indexOf(letter)!=-1; why -1?

1 Answer

Matthew S
Matthew S
8,626 Points

An index is considered a number starting from 0 as the first index and onwards. -1 is an index that doesn't exist, so "!=-1" means if the index does not equal to not existing (hope that makes sense)