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 (Retired) Creating the MVP Storing Guesses

Alexander Nowak
Alexander Nowak
498 Points

What does 'return isHit;' do? Why do we need it? and how do I know to use to in my code?

.

2 Answers

As you see the function applyGuess is public boolean, which means it returns a boolean value. isHit stores a boolean value an by using "return" you make sure the function returns that value.

Alexander Nowak
Alexander Nowak
498 Points

Returns that value to where?

Thanks!

It returns it to the code that invokes it. I am not sure of what the full code is because I couldn't see it but I see there is a true/false that gets printed in the console. I am however not sure if there is a print statement somwhere. For more info on what "return" does read this.