Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Shivang Chaturvedi
2,600 PointsTotally Lost on ScrablePlayer Challenge !!
Need some help with the 'For Each loop' implementation in this challenge.
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
// Adds the tile to the hand of the player
mHand += tile;
}
public boolean hasTile(char tile) {
return mHand.indexOf(tile) > -1;
}
}
1 Answer

Robert Richey
Courses Plus Student 16,352 PointsHi Shivang,
Let's start by making the getTileCount
method signature. Since it's going to return a count, we'll set the return value as an int
.
public int getTileCount(char tile) {
}
We want to return a count of the number of tiles a player has that matches the given tile.
public int getTileCount(char tile) {
int count = 0;
// for each letter in mHand
// if letter matches tile
// increment count
return count;
}
If you need a refresher on setting up the for ... each loop, at about 1:08 in the video Current Progress, Craig explains how to do this.
Hope this helps,
Cheers