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 trialSiu KWAN Yuen
Courses Plus Student 2,898 Pointsassign 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
Peter Danglay
861 PointsI 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
Siu KWAN Yuen
Courses Plus Student 2,898 PointsYa, but you cannot game.stringProgress it or game.getProgress it.
Peter Danglay
861 PointsIs 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.
Peter Danglay
861 PointsPeter Danglay
861 PointsDon't take my word for it