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 trialdlpuxdzztg
8,243 PointsWhat do these lines of code do?
- private Game mGame; (Specifically, why do we put Game before mGame?)
- char guess = guessAsString.charAt(0);
- return mGame.applyGuess(guess);
Help is appreciated!
2 Answers
Karen Freeman-Smith
29,248 Pointsprivate Game mGame; (Specifically, why do we put Game before mGame?) "Game" is the type of variable you are declaring - like String or Int it says what kind of object "mGame" is supposed to be.
char guess = guessAsString.charAt(0); You have a variable named "guessAsString" and are taking only the first character of that string to assign to the variable "guess".
return mGame.applyGuess(guess); "applyGuess" is a method of the "Game" object. (mGuess got that method as part of the variable declaration in the first line above). This last line will return whatever that method does after testing your "guess" character (probably a true/false...is the guess correct?)
Karen Freeman-Smith
29,248 PointsI think it's the first letter you ENTER... so if you typed more than one character as your guess, it only looks at the first letter you typed. But then it checks to see if it's part of the word/phrase you are guessing... test it with a letter that is NOT in treehouse.
dlpuxdzztg
8,243 PointsOhhhh... Thanks!
dlpuxdzztg
8,243 Pointsdlpuxdzztg
8,243 PointsThanks for the help so far! But I have another problem involving: char guess = guessAsString.charAt(0);. When it asked me to enter a letter, I entered a letter that isn't 't' but is in treehouse. However, It still printed "We got a hit!".
This confuses me because you said i'm only taking the first letter of the word and assigning it to "guess".