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 trialJacob Luallen
1,947 PointsTrouble with hangman and simple boolean statement.
I need to set up the hasTile method so it will return true if the hand(mHand?) contains the tile and false if otherwise. I should only need a simple boolean statement right? I don't know what I am doing wrong.
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) {
boolean hasTile = mHand.indexof(tile) >= 0;
return false;
}
}
1 Answer
Cristian Altin
12,165 PointsIn the hasTile function you are always returning false if you write return false;
You should return the boolean variable so that it will return the wanted outcome.
p.s. also be aware of indexOf case sensitivity
Jacob Luallen
1,947 PointsJacob Luallen
1,947 PointsThank you.
Cristian Altin
12,165 PointsCristian Altin
12,165 PointsIt's been a pleasure! If my answer brought you to the solution please remember to mark it.