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) Delivering the MVP Validation

Joanna van der Veen
Joanna van der Veen
543 Points

Keep getting 'missing return statement' error

Hi,

I've followed along with the video but I keep getting an error and can't see how to solve it:

public boolean applyGuess(char letter) { // This creates a method that returns a true or false value depending on whether the input, which is a letter, is in the answer or not. It defines what should happen in each case. letter = validateGuess(letter); boolean isHit = mAnswer.indexOf(letter) >= 0; if(isHit) { mHits += letter; } else { mMisses += letter; } return isHit; }

Sorry, I couldn't figure out how to get a screenshot on here..

Any help much appreciated!

I will show you how to format your code: If you type something other than code before your code go ahead and hit enter and follow these instructions:

Type in the accent key that is above the Tab key three times in a row followed by the keyword java and hit enter twice. Next, with at least one space in between type the accent key three more times and then hit enter. Next copy and paste your code in between the accent marks and then submit.

3 Answers

If it were me I would do this code a little differently:

boolean isHit = mAnswer.indexOf(letter) >= 0;

I would do it something like this:

boolean isHit;
if(mAnswer.indexOf(letter) >= 0)
  isHit = true;
else
  isHit = false;

When you get en error, please always post it here. And also post other parts of your code, because from first view, the code looks ok.

For formatting, look at the "Markdown Cheatsheet" (link below the field where you write your post/question). For java write "java" where you findd "html" in the exmple of the Markdown Cheatsheet.

Oh sorry, I overlooked the title of your post, because I clicked on the little notification link.