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 trialaroshinemunasinghe
5,649 Pointsprogramming help
Hi there
I am doing Hangman (not the same like Treehouse). The problem is this:
public void convertAndCheckTheAnswer(String userGuess) {
String display = "";
for (char a : answer.toCharArray()) {
char convert = '-';
char uGuess = userGuess.charAt(0);
if (uGuess == a) {
convert = uGuess;
hit++;
}//end if
miss++;
display += convert;
}//end for
showDisplay(display);
collectPoints(hit);
sketchHangMan.sketchPoorHangMan(miss);
}//end convertAndCheckTheAnswer
Here is the problem: The answer is : tree When user has entered a letter t, then if state checks = TRUE gives one point from hit++. OK thats great, BUT! It also add miss++ and sent to object SketchHangMan (to draw Hangman :D ) saying sorry wrong.
I think it because I put miss++ in the for loop? But what shall I do? Shall I change function to int instead void?
1 Answer
Steve Hunter
57,712 PointsHi there,
I think you want miss++
inside the else
part of your if
statement.
if (uGuess == a) {
convert = uGuess;
hit++;
} else {
miss++;
}
Steve.