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 trialJacqueline Haggett
1,135 PointsWhen is the applyGuess method actually called?
The previous code actually called the applyGuess method when the statement return game.applyGuess(guess); ran. Now it doesn't seem like method is actually getting called to run, isHit is just being set equal to that method with guess as the parameter. Does the applyguess method execute when isHit is set equal to it? If so that feels weird that you don't really seem like you are calling the method.
public boolean promptForGuess() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a letter: ");
String guessInput = scanner.nextLine();
char guess = guessInput.charAt(0);
boolean isHit = false;
try {
isHit = game.applyGuess(guess);
} catch(IllegalArgumentException iae) {
System.out.println(iae.getMessage());
}
return isHit;
}
1 Answer
Daniel Phillips
26,940 PointsIt's getting called in the try block. You might be mixing up the concept of passing a function as an object like you can in JavaScript. In Java, this is just a function call that has its boolean return value assigned to the variable isHit.