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 trialwelsen ho
1,330 Pointsmethod seems wrong...
what is wrong with my code, and what does it mean it wants me to return my result in expression?
public class ScrabblePlayer {
// A String representing all of the tiles that this player has
private String tiles;
private String misses;
public ScrabblePlayer() {
tiles = "";
misses = "";
}
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 isTiles = tiles.indexOf(tile) != -1;
if(isTiles){
tiles += tile;
}else{
misses += tile;
}
return isTiles;
}
}
1 Answer
Yanuar Prakoso
15,196 PointsHi Welsen
Your task in the challenge only required you to return TRUE or FALSE depending on whether the char tile is in the String tiles or not. You can just using your boolean expression as return variable since your method already stated as Boolean right? Here how you should do it:
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
return (tiles.indexOf(tile) != -1); //<-- it will return Boolean TRUE or FALSE
}
Yes it is true that String method indexOf should return an int type as answer. However, the statement (tiles.indexOf(tile) != -1a0 is like an if statement which will return a boolean type value TRUE if tile is in the tiles and FALSE if it is not.
I hope this will help a little.