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

Wan Nor Adzahari Wan Tajuddin
Wan Nor Adzahari Wan Tajuddin
2,438 Points

What does it mean when it says "try returning the result of the expression"

I don't understand what the questions wants. Please help. Take a look at my code if there's any mistakes on my part.

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 hadTile = tiles.indexOf(tile) > 0;
    if (hadTile) {
    return true;
    } else {
      return false;
      }
  }

}

1 Answer

Steven Parker
Steven Parker
231,184 Points

Just return the expression result instead of storing it.

The challenge says, "I'd like you to practice returning the result of the expression that uses the index of a char in a String." So instead of copying the result of your expression into a new boolean variable, and then testing that to determine what to return, just return the result of your expression directly. This will compact your code down to a single line.