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.

Brian Maimone
Courses Plus Student 1,644 PointsOne Hangman error, would appreciate help.
cannot find symbol, boolean isHit = prompter.promptForGuess(); symbol: method promptForGuess() ; location: variable prompter of type Prompter. We're calling a method on an object which I'm not clear about. My code below:
public class Hangman {
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game); //pass game object ,created above, into Prompter; now Prompter knows about game logic
boolean isHit = prompter.promptForGuess(); //call method on prompter object
if (isHit) {
System.out.println("We got a hit"); }
else {
System.out.println("Whooops that was a miss"); }
}
}
import java.io.Console;
public class Prompter {// object to do i/o
private Game mGame;
public Prompter(Game game) {//constructor takes Game object called game
mGame = game; //set mGame to what was passed in (game)
}
public boolean prompForGuess() { // returns T/F
Console console = System.console();// Console is a class importing from java.io
String guessAsString = console.readLine("Enter a letter: ");
char guess = guessAsString.charAt(0);
return mGame.applyGuess(guess);//call applyGuess method, pass in guess(1st char from string)return T/F
}
}
public class Game {
private String mAnswer;
private String mHits;
private String mMisses;
public Game(String answer) {
mAnswer = answer;
mHits = "";
mMisses = "";
}
public boolean applyGuess(char letter) {//method to apply a guess towards the puzzle, takes a letter, returns T if hit, F for miss
boolean isHit = mAnswer.indexOf(letter) >= 0; //boolean value knows whether or not guess is good, mAnswer = Treehouse
if (isHit) {
mHits += letter; //update hit count
} else {
mMisses += letter;
}
return isHit;
}
}
2 Answers

Craig Dennis
Treehouse TeacherHmmm.... prompForGuess
seems to be missing something. Dot your i's and cross your t's.

Brian Maimone
Courses Plus Student 1,644 PointsThanks Craig. Can't believe I didn't catch that one.

Craig Dennis
Treehouse TeacherNo problem...years of making mistakes, makes those easier to find ;)