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 trialBrad Palmer
2,460 PointsI am stumped and I don't know how to ask for help here!
public boolean hasTile(char tile) { // TODO: Determine if user has the tile passed in boolean gotTile = tiles.indexOf(tile) != -1; if (gotTile) { tiles += tile; } else { gotTile = false; } return gotTile; } // this obviously is wrong. Help!
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) {
// TODO: Add the tile to tiles
tiles += tile;
}
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
boolean gotTile = tiles.indexOf(tile) != -1;
if (gotTile) {
tiles += tile;
} else {
gotTile = false;
}
return gotTile;
}
}
1 Answer
Yanuar Prakoso
15,196 PointsHi Brad
The challenge only asks you to return True if tile indeed inside tiles and False if tile is not in the tiles String. You don't have to add tile into the tiles. You can just do this like this:
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
return (tiles.indexOf(tile)!=-1);
the method already stated it will return a boolean. And the (tiles.indexOf(tile)!=-1) part will return boolean (True or False) thus you can just put it in the return section of the method's code.
I hope this can help a little