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 trialAlvaro Lopez
2,901 PointsI am not able to solve this challenge, it says it suppose to return 1 but only returns 0
I cannot solve this challenge, it says it suppose to return 1 but only returns 0
public class ScrabblePlayer {
private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public int getTileCount(char t){
int count = 0;
for (char letter : mHand.toCharArray()){
if (mHand.equals(letter)) {
count++;}
}
return count;
}
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;
}
}
2 Answers
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHello, you're very close. It looks like your if statement to see if they are equal is what is throwing it off. What it looks like it is trying to do is check to see if mHand is equal to the char chosen,
try this
public int getTileCount(char t) {
int count = 0;
for (char letter: mHand.toCharArray()) {
if (letter==t) {
count++;
}
}
return count;
}
Alvaro Lopez
2,901 PointsIt make sense, thank you!
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse TeacherRob there is a space between
count
and++
, I think that probably won't work....Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsRob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsYou were right about that one, good catch. I was able to get it to work in the code challange, but it must have transposed in copying it over. Cntl V and Cntrl C are dangerously close to space.
Thanks!