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 trialDorka Tamas
5,085 Pointsmissing return statement }
Hi,
I tried to perform the task as it is in the video, but I got this message:
Game.java: 19: missing return statement }
I think I have all the curly brackets, so I am not sure what the problem is.
Thanks in advance!
3 Answers
adamabdulghani
7,864 PointsGame.java: 19: missing return statement
So the error message is telling you that there is no return statement.
Check the applyGuess method, you've set the return type of that method to boolean, so this method should return a boolean. By the looks of it, i believe you want to return the isHit boolean, check the snippet below.
public boolean applyGuess(char letter) {
boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit) {
mHits += letter;
} else {
mMisses += letter;
}
return isHit;
}
Happy coding & Good luck! :-)
Jennifer Nordell
Treehouse TeacherIt looks like this code is supposed to return a boolean. But you're not actually returning anything. Try either making it void or return a boolean.
public boolean applyGuess(char letter) {
boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit) {
mHits += letter;
} else {
mMisses += letter;
}
}
IE you may need a return statement to return the isHit value.
Dorka Tamas
5,085 PointsThanks. It works now. :)
Dorka Tamas
5,085 PointsDorka Tamas
5,085 PointsThis is my code:
public class Game { private String mAnswer; //What is a member variable? private String mHits; private String mMisses;
}