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 PointsStuck on Scrabble char method challenge
Hi,
I am supposed to fill out the addTile method so that it takes the char that is passed and adds it to the mHand member field. Not really sure what to do! Here is my code. Thanks for helping!
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
boolean isHit = mHand.indexOf(tile) >= 0;
if (isHit) {
mHand += tile;
} else {
mHand += tile;
}
return isHit;
// Adds the tile to the hand of the player
}
public boolean hasTile(char tile) {
return false;
}
}
1 Answer
Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 PointsHi Gabriel.
You have to write into the variable with the argument that's passed to the method.
mHand += tile;
As you can see the scope of the variable mHand it's global for the whole object and the "tile" is passed to the method.
Hope this helped.
Happy Coding!!!
nWEBd