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 trialCarter Hawes
1,143 PointsNeed someone to check my code for JAVA hangman. Can't find errors after checking with video code for 1 hour.
I need somebody to check my code and tell me what's wrong/ what to do. I have even tried copying the code exactly and it says tat what I'm doing is an illegal move. Can somebody show me what I'm missing? https://w.trhou.se/u883vyvc4u
1 Answer
Dave StSomeWhere
19,870 PointsI see 5 issues that once fixed should get you rolling:
Four issues in getCurrentProgress() method - marked with comments:
public String getCurrentProgress() { // lower case g
String progress = "";
char display; // declare before loop
for (char letter : answer.toCharArray()) {
display = '-';
if (hits.indexOf(letter) != -1)
display = letter;
progress += display; // move into loop
}
return progress; // move into method
}
One issue in your main() method
public static void main(String[] args) {
// Your incredible code goes here...
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
prompter.displayProgress();
boolean isHit = prompter.promptForGuess();
if (isHit) {
System.out.println("We got a hit!"); // caps on System
} else {
System.out.println("Oops missed");
}
prompter.displayProgress();
}
Happy hanging
Carter Hawes
1,143 PointsCarter Hawes
1,143 PointsThank you very much! This helped me a lot.