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

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".