App Lab - Game Help!

I’m trying to finish up a hangman game, and I’ve ran into a couple of problems. What I’m trying to do is check the incorrect guess, and have a running tally. What is happening now is that the code counts them as incorrect and stops any progress that is made in the game.

Here’s a link to the project:

Thanks in advance!

I tried out the game, but unfortunately I’m not much help with debugging your code. You have a great start though! Do you mind if I share your project with some students to see if they can come up with any suggestions?

I found a couple of problems that I have fixed.

In resetGuessInput make sure you set the text of the guessInputText to an empty string ("") and not a space (" ").

Your wrongCounter is getting updated even when the user enters a correct guess because not all letters in the word are equal to the guess letter. For example in the word apple, when the user enters ‘p’, the wrongCounter gets incremented when the first letter in the word ‘a’ is checked. The second and third time around the loop, the guess is correct, so wrongCounter is not updated. Next time through the loop the wordCounter gets incremented again because the letter ‘e’ is checked against the guess. Your else part should be outside the loop. I corrected that by using a boolean flag. If the user enters a correct guess, the flag is set to true and it won’t go into the else part for any other check that is being made. I hope this makes sense.

Here is the link to the correcterd program: https://studio.code.org/projects/applab/lZxNlMKF7ZAs9QvThD5Txw

1 Like

Thank you so much! I’ll finish up the incorrect guess counter and I think it’s all good to go.