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

Java Java Objects Creating the MVP Scrabble Tiles

Zachary Martin
Zachary Martin
3,545 Points

incompatible types: int cannot be converted to boolean

I cant get task two to run can anyone see whats wrong with my code;

ScrabblePlayer.java
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 isHit = tiles.indexOf(tile);
    if(isHit) {
    return true;
    }
  }

}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The indexOf returns the index that what you're searching for is found in the string. The index is an integer which you are trying to assign to a variable declared as boolean.

Here's some doucmenation

And here's a hint :bulb: : If the character (or substring) was not found, a negative 1 (-1) will be returned.

Hope this helps! :sparkles: