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 Creating the MVP Current Progress

Siu KWAN Yuen
PLUS
Siu KWAN Yuen
Courses Plus Student 2,898 Points

assign new value to field using method

In this lesson, I saw Craig uisng the getCurrentProgress method to check out if the guess matches the answer, and show them the letter if it is matched. But why do we declare "String progress", the value returned by the method, inside the method. Wouldn't we lost the "String progress" after the method is called?

2 Answers

I might be wrong but this is how I understand it in the code it will call the method and get the value of the value it returned

Don't take my word for it

Siu KWAN Yuen
PLUS
Siu KWAN Yuen
Courses Plus Student 2,898 Points

Ya, but you cannot game.stringProgress it or game.getProgress it.

Is the code you are talking about?

public boolean isWon(){

return getCurrentProgress().indexOf('-') == -1;

}

if it is this is how it works it will get the value of the method whatever is returned and check to see if it does not contain '_' if it doesn't contain it gives true if it does contain it will give false.