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 trialGabriel E
8,916 PointsNot sure about hasTile method on challenge
Hi there,
On this challenge, I'm supposed to return true if scrabble hand has the tile, and false if it doesn't. Not quite sure what I'm doing wrong. Here's my code. Thanks for the help!
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
boolean hasTile = mHand.indexOf(tile) >= 0;
mHand += tile;
// Adds the tile to the hand of the player
}
public boolean hasTile(char tile) {
if (isHit) {
hasTile += tile;
return true;
} else {
hasTile -= tile;
return false;
}
return hasTile;
}
}
1 Answer
rtholen
Courses Plus Student 11,859 PointsAssuming this is all of your code. Then a couple of hints:
- Take a look at isHit. This is not defined or set anywhere.
- You have a local variable hasTile and a function hasTile() and are possibly confusing the two.
- The function hasTile() should be doing what you appear to be trying to do in the first line of addTile(), while the function addTile() should only be adding tiles to the mHand String. Each function should accomplish one task.