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

Shiva Lowy
seal-mask
.a{fill-rule:evenodd;}techdegree
Shiva Lowy
Full Stack JavaScript Techdegree Student 3,240 Points

I have been trying to complete this challenge for TWO DAYS!!!

I feel so lost and dumb. I have tried everything and I do not know what it is I am doing wrong. I am fairly new at this so I am the biggest noob on the planet.

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;

    // TODO: Add the tile to tiles

  }

  public boolean hasTile(char tile) {
    return tiles.indexOf(tile)!=-1;
  // TODO: Determine if user has the tile passed in
    return false;
  }

}

2 Answers

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

Hi there! First off, you're doing much better than you think you are, and I can prove it! You have the solution already written. It's there and it works. But you have an extra line which is causing a compiler error.

Here is the offending line:

return false;

If I remove that line, your code passes both steps :thumbsup:

You may not have two return statements inside a function without two separate ways to get to those return statements. Remember, once a return statement is hit, the function ceases execution.

So, you could have something like this:

if(this) {
  return something;
} else {
  return somethingElse;
}

This would be an example of two return statements which are gotten to by two separate paths.

On a side note, remember that learning is not linear. There's a reason it's called a "learning curve". You don't always get out of it what you put into it. What you're looking for is that moment when something clicks and it suddenly makes sense. It will come. I call them my "light bulb" moments :bulb:

Hope this helps, but let me know if you have any more questions! :sparkles: And hang in there!

Shiva Lowy
seal-mask
.a{fill-rule:evenodd;}techdegree
Shiva Lowy
Full Stack JavaScript Techdegree Student 3,240 Points

Oh my gosh!!! You made me see the light!! You are the best teacher ever. Thank you!!!! I really appreciate your motivation and kind words.