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 trialJustyn Jackere
561 PointsBased on my code, am I doing something wrong? Or is there something I'm missing?
Tried if statements, but they aren't allowed in this challenge. I've even tried adding an answer to the ScrabblePlayer constructor since I don't see any answer which wold allow me to get a return value of true or false.
In addition, when I attempt to index yesHasTile = tiles.indexOf(tile) != -1; I receive a syntax error saying int and char types are incompatible. I don't see any int variable anywhere. I've been working on this from 10 AM this morning until 5:24 PM this afternoon (Eastern Time, USA). I'm beginning to lose my patience.
Thank you in advance for any advice or help with this challenge. :-)
public class ScrabblePlayer {
// A String representing all of the tiles that this player has
private String tiles;
public ScrabblePlayer() {
tiles = "";
}
public String getTiles() {
return tiles;
}
public void addTile(char tile) {
tiles += tile; // TODO: Add the tile to tiles
}
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
boolean yesHasTile = tiles.indexOf(tile);
return true;
return false;
}
}
1 Answer
Tabatha Trahan
21,422 PointsTry this:
public boolean hasTile(char tile){
return tiles.indexOf(tile) >= 0;
}
if the tile is in the string tiles, indexOf will return the position within the string. If the tile is not in the string tiles, then it will return -1. When you throw in the comparison operator, you will return a boolean, which is what you are looking to do here.