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

Jordan Botts
Jordan Botts
1,860 Points

I am having trouble understanding what needs to be done to when it says try returning the results of the expression.

I am currently returning true if the character that is being pushed in from hasTile is in the current hand and I am returning false if it is not. Not sure why this is not working but the challenge says "Try returning the results of the expression". Which I am a bit confused about.

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) {
    tiles += tile;

  }

  public boolean hasTile(char tile) {
    boolean currentHand = tiles.indexOf(tile) != -1;
    if (currentHand) {
      return true;
    } else {
      return false;
    }

  }

}

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

it is telling you to ditch the if statement block and just return the conditional statement, ie if you were to put return 1 > 2, the return value would be false. there is no need to say if true, return true, if false, return false like you have. the statement will be evaluated and whatever it is will be the return value.

Jordan Botts
Jordan Botts
1,860 Points

Thanks James! That helped a lot. I removed the if statement and added "return currentHand;" after "boolean currentHand = tiles.indexOf(tile) != -1;" and it worked! Is that what you had in mind? Or is that still redundant?