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 trialDiana Prince
Courses Plus Student 546 PointsBummer! While you could definitely solve this using an if statement, try returning the result of the expression.
I dont understand where i am wrong i tried returning the variable but it is still showing me an error please help
public class ScrabblePlayer {
// A String representing all of the tiles that this player has
private String tiles;
private String correctTile;
private String falseTile;
public ScrabblePlayer() {
tiles = "";
correctTile = "";
falseTile = "";
}
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 isCorrectTile = tiles.indexOf(tile) != -1;
if(isCorrectTile){
correctTile += tile;
}else{
falseTile += tile;
}
return tiles.indexOf(tile) != -1;
}
}
1 Answer
Ronald Williams
Java Web Development Techdegree Graduate 25,021 PointsYou almost have it there. You do not need to use an if statement. You only need the following returned: tiles.indexOf(tile) != -1; This statement is either true or false. Returns true if the index of the character is >= 0 and returns false if the index of the character is -1 (which we know -1 means that the string tiles does not contain the tile). This is how the method indexOf works. https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-int-
public boolean hasTile(char tile) {
// TODO: Determine if user has the tile passed in
return tiles.indexOf(tile) != -1;
}
foxtails
3,655 Pointsfoxtails
3,655 PointsThanks! Was stuck on the same question.