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 Current Progress

Kat Kovalsky
PLUS
Kat Kovalsky
Courses Plus Student 686 Points

How our input letter get in " letter" in getCurrentProgress method?

Maybe this is a very stupid question but i really cant understand

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Kat,

if I understand your question correctly the input letter and the letter inside the getCurrentProgress() method are not the same.

Inside the getCurrentProgress() you are creating a for loop that goes over every character inside the mAnswer (after converting String mHand into a character array). So you can read the code of the for loop like this:

    public String getCurrentProgress() {
        String progress = " ";
        for (char letter : mAnswer.toCharArray()) {
// assign every single character of the answer array ("-t-r-e-e-h-o-u-s-e-")
// to a variable called "letter" (not the input letter)
            char display = '-';

            if (mHits.indexOf(letter) >= 0) {
         // if the "letter" from the for loop is inside mHits
                display = letter; 
         // display this letter
            }
            progress += display;
        }
        return progress;
    }

So you are not using the letter from users input. Instead you create a new variable "letter" to strore characters from mAnswer to compare them with characters in mHit. Same names but different locations.

Does it make sense?

Grigorij

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

You are welcome !

See you in the forum

Grigorij