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 trialRob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsWhat is wrong with this code?
public class ScrabblePlayer { private String mHand;
public ScrabblePlayer() {
mHand = "";
}
public String getHand() {
return mHand;
}
public void addTile(char tile) {
mHand += tile;
}
public boolean hasTile(char tile) {
boolean handContains =mHand.indexOf('tile') >= 0;
if (handContains) {
return true;
} else {
return false;
}
}
}
Hello Everyone, the code above is giving me trouble, this looks to be right however it keeps telling me there is a syntax error then when I try to preview it to see what is wrong it shows me a blank template with only the black background. A error usually occurs at this time and it asks me to launch the challange again, I looked to see if it was a loop that was crashing it but that would make no sense as there is no loop in the code that could cause that.
Any help would be greatly appreciated.
Thanks.
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
}
public boolean hasTile(char tile) {
return false;
}
}
2 Answers
Robert Richey
Courses Plus Student 16,352 PointsHi Rob,
I can't pinpoint the syntax error, but I can show you code that works for this challenge. My opinion is that your code is fine but it's not passing their built in test. Edit: as Craig points out, the syntax error is tile being wrapped in single quotes.
public boolean hasTile(char tile) {
if (mHand.indexOf(tile) >= 0) {
return true;
} else {
return false;
}
}
Craig Dennis
Treehouse TeacherYou have 'tile' in single quotes. Sorry the compiler error didn't show up. I will look into it!
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsRob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsThank you,
I Tried it that way, and it did work.
Thanks for the help!