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.

Java Java Objects (Retired) Creating the MVP Storing Guesses

In the Storing Guesses video, why is mAnswer= answer, mHits = "", and mMisses = "" ?

I don't understand.

2 Answers

When you say mAnswers = “” and mHits = “” you are setting these variables so that they are an empty string. By setting the values of mAnswer and mHits, you are making sure that you have something to work with incase you try to manipulate it in way that means you think it has data but it really does not. For example, if you try to display the contents of it without any data you will get an error, but you won’t if you set it to an empty string. Setting variables can be a good idea when you create them because you have control over what is stored in that variable. Otherwise it is filled with ’garbage data’

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

When you create a game, you first need to know the answer to the game so that you can see if guesses are right or wrong. You pass in answer as a parameter when you create the game and then set it as "mAnswer" to keep track of it.

You start "mHits" and "mMisses" as an empty string when you first create the game because there wouldn't have been any guesses/misses yet. Later on when a player makes a guess and hits/misses, you will then change what is inside "mHits" and "mMisses".