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 trialJeremy Hutson
4,371 PointsPlease read through my code and tell me what I'm missing. So frustrated. Videos move too quickly for me.
Here is my code for Gama.java, which is where I get an error message. Assuming that Hangman.java and Prompter.java do not contain errors.
Error is in line 25: error: cannot find symbol letter = validateLetter(letter);
symbol: method validateLetter(char)
Thanks!
[Code starts below] public class Game { public static final int MAX_MISSES = 7; private String mAnswer; private String mHits; private String mMisses;
public Game(String answer) { mAnswer = answer; mHits = ""; mMisses = ""; }
private char validateGuess(char letter) { if (! Character.isLetter(letter)) { throw new IllegalArgumentException("A letter is required"); } letter = Character.toLowerCase(letter); if (mMisses.indexOf(letter) >= 0 || mHits.indexOf(letter) >= 0) { throw new IllegalArgumentException(letter + " has already been guessed"); } return letter; }
public boolean applyGuess(char letter) { letter = validateLetter(letter); boolean isHit = mAnswer.indexOf(letter) >= 0; if (isHit) { mHits += letter; } else { mMisses += letter; } return isHit; }
public String getCurrentProgress() { String progress = ""; for (char letter : mAnswer.toCharArray()) { char display = '-'; if (mHits.indexOf(letter) >= 0) { display = letter; } progress += display; } return progress; }
public int getRemainingTries() { return MAX_MISSES - mMisses.length(); } }
7 Answers
Jon Kussmann
Courses Plus Student 7,254 PointsHi Jeremy,
You are calling validateLetter(), but the method you have written is called validateGuess()
I would change one of them to match the other.
Will Long
5,449 Pointsyou have done more javascript than I have, keep up the good work, but if the videos are too fast, you can change how fast the video is right next to the volume control.
Jeremy Hutson
4,371 PointsThank you!!! I wonder why I typed that? lol
This is all completely new to me. Taking a Java course at community college next month, and struggling to dive into the language (have worked through Codecademy courses, some other courses here on Treehouse, and watching videos on Lynda and Udemy. The programming challenges in the book Absolute Java are way above where I'm at, but I'm going to work slowly through them as I keep reading the textbook.
Jeremy Hutson
4,371 PointsBy the way, how do we format our code here in the forum?
Will Long
5,449 PointsI think you have to add your code in a link... IDK
Jon Kussmann
Courses Plus Student 7,254 PointsWhen you "add comment" or "add and answer" there is a link that says "Markdown Cheatsheet" that tells you how to format posts. It will take a couple of tries to get it right, but I often use it for reference.
Jeremy Hutson
4,371 PointsOkay. I'll try to figure that out. Thanks again.
Jeremy Hutson
4,371 PointsExcellent. Thanks again Jon. I will have many more questions, I'm sure. Thank goodness for this great forum.
Jeremy Hutson
4,371 PointsOkay, changing my line 13
private char validateGuess(char letter) { to ...validateLetter... etc.
fixed the error.
I'm going to go back to the video and see where it was that I missed that.
Jeremy Hutson
4,371 PointsLOL!!! Not my fault. Too funny. I should have just kept watching. APME (All Programmers Make Errors).
Jeremy Hutson
4,371 PointsJeremy Hutson
4,371 PointsJon, do you mean private char validateGuess(char letter)
That is actually what Craig has written, unless I'm mistaken or missing something.
This is actually a significant amount of code for a beginner. It would be so helpful to have a place to go to double check our code. I could just watch and not use Workspaces, like someone else has mentioned, and then go back and do the course with Workspaces, but I'm trying to conserve time (which is probably my mistake).