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 Java Objects Creating the MVP Prompting for Guesses

Md shujaul Haque
Md shujaul Haque
839 Points

return game.applyGuess(guess) how this work and guess is pass to another method ? dont understand this line .

In prompt class

return game.applyGuess(guess) how this is working, did not understand this line of code and how "guess" passing through ?

1 Answer

Randy Duncan
Randy Duncan
1,026 Points

In an application code is executed line by line so he already declared that the char that accepts the argument of guessInput which is "0" , he named that guess....so once the code in that line is executed it then moves on to the last line in the method with the return value... being that the guessInput is already assigned to the variable guess in the promptForGuess scope he can now use it any where after he declared it as long as its in that scope..... so in theory when the executed line 14 he can use it in any line after which is what he did, he called the applyGuess method from the game class and he the passed in the guess that was assigned. Hope that helps as i'm also learning and i'm not a master yet.