App Lab - Project Help!


#1

Hello,

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!


#2

I found a couple of problems that I have fixed.

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

  2. 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