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

Sachini Hansini Nawalaella
2,842 Pointssrabble task 2
i can not get answer right? i want to know where did i get wrong
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 += "t";
}
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
boolean hasTile = tiles.indexOf(tile)
if (hasTile = -1) {
return false;
} else {
return true;
}
}
2 Answers

Sachini Hansini Nawalaella
2,842 PointsThat line also give me a error message but i was able to find my error. Thank you Richard Lambert

Richard Lambert
Courses Plus Student 7,180 PointsHello mate,
I like your thinking and can see what logic you're trying to implement within the .hasTile(char tile)
method. With just a few alterations you would have a correct implementation:
public boolean hasTile(char tile) {
int hasTile = tiles.indexOf(tile); // .indexOf(char c) returns a value of type int not boolean
if (hasTile == -1) { // == for test of equality not = for assignment
return false;
} else {
return true;
}
}
BUT, this is not the implementation the Treehouse Java test engine is expecting to see.
Hope this helps

Sachini Hansini Nawalaella
2,842 Pointsi still can not get the answer

Richard Lambert
Courses Plus Student 7,180 PointsTry this Sachini Hansini Nawalaella:
public boolean hasTile(char tile) {
return tiles.indexOf(tile) != -1;
}