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.
I keep getting an error of cannot find symbol when trying to do boolean isTile = addTile.indexOf(tile);
Question: Correct the existing hasTile method to return true if the tile is in the tiles field, and false if it isn't. You can solve this a few ways, however, I'd like you to practice returning the result of the expression that uses the index of a char in a String.
Error msg: ./ScrabblePlayer.java:20: error: cannot find symbol boolean isTile = addTile.indexOf(tile); ^ symbol: variable addTile location: class ScrabblePlayer
AddTiles is a method with no return value. The variable this.tiles is the String representing all of the tiles that this player has. Try that with indexOf.
Andy StevensFront End Web Development Techdegree Graduate 20,417 Points
indexOf will return -1 if the value is not found in the String as such your code should evaluate whether the String is greater than or equal to 0 i.e. is a char found.
I would write something like
return tiles.indexOf(tile) >= 0;
Let me know if this answers your question.