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 trial

Java

Kenneth Emmanuel Kouadio Ziguy
PLUS
Kenneth Emmanuel Kouadio Ziguy
Courses Plus Student 1,125 Points

I am not sure about what really happens in the body of our promptForGuess() method

I am going to list below what I understand in the code written below. I would please like to get correction if my understanding is wrong.

public boolean promptForGuess(){

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a letter: ");

String guessInput= scanner.nextLine();

char guess = guessInput.charAt(0);

return game.applyGuess(guess)

}

Scanner scanner = new Scanner(System.in); allows the creation of an object from the Scanner class which then allows us to use the scanner class and its methods

System.out.print("Enter a letter: "); prints to the screen ""Enter a letter: //input from the user of the code(player)"

whatever input the player has entered is going to be stored in our guessInput variable because of this code : String guessInput= scanner.nextLine();

char guess = guessInput.charAt(0); this allows us to store the first character from the input the player has entered

and this code return game.applyGuess(guess) returns wether the player has entered a correct guess(true) or an incorrect guess( false)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You haven't linked the project you're working on, but your understanding of the code seems pretty spot on to me. The only thing I can't confirm is the last line as I don't have the code for the Class you're using with the applyGuess method. That being said, given that your understanding of the previous lines is correct, my guess is that your understanding of the last line is also correct.

Happy coding! :sparkles:

Kenneth Emmanuel Kouadio Ziguy
PLUS
Kenneth Emmanuel Kouadio Ziguy
Courses Plus Student 1,125 Points

Thank you very much for the help! I want to link the project I am working on but I do not know how to do that