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 trialMUZ140151 Gilbert Chapara
2,621 Pointscreating an mvp
am running this code and its giving me a bummer may somebody help me where iam wrong.
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) {
if(mHand.indexOf(tile)){
return true;
}else{
return false;
}
}
2 Answers
Chase Marchione
155,055 PointsYou're close!
- Counting your opening and ending curly braces: you need one more at the end of the class, to match the opening brace from your class header.
- Your if statement is where things get tricky. You want to check if the indexOf the tile is greater than or equal to 0 (or, greater than -1.) This is a boolean (true or false logic) way of testing whether the value is in the mHand String or not, and if an index for that value is indeed in that String (certainly, if there is an index for that value in our String, it is 0 or greater!).
if(mHand.indexOf(tile) >= 0)
Hope this helps!
Craig Dennis
Treehouse TeacherAlso remember you can return the expression and avoid the if block all together!