The Hidden Word
Time for another project! This checkpoint puts the arrays and loops from the last two lessons to work, together with everything you learned before them. As in the first checkpoint, the instructions say what the program should print, and how you write it is up to you. And as there, each exercise also runs your program with other data, so it has to work everything out from the constants at the top.
The project. Hangman is a word game for two. One player thinks of a secret word, and the other guesses it one letter at a time. Each right letter is revealed in the word, and each wrong one is a mistake, which costs a life. Over three exercises, your program will show the word as the guessing player sees it, list the wrong guesses, and decide whether the game is won or lost.
The data. The constant word holds the secret word, in capital letters, and guesses is an array of the letters the player has guessed so far, in the order they tried them.
The task. Print the word with a space between the letters, and with an underscore _ in place of every letter the player hasn't guessed yet. Below it, print how many of the word's letters are still hidden. For this game, the program prints:
_ A _ A S _ R _ _ T
Hidden letters: 5A letter that's in the word more than once is revealed everywhere at once: the player guessed A, so both A's of JAVASCRIPT are shown. And each hidden place counts, so with word = "BANANA", the program prints _ A _ A _ A and Hidden letters: 3.
A tip: remember that += also adds text to the end of a variable, and that a loop can go through the characters of a text, as you saw in the lesson on loops.
Instructions
Print the word as the guessing player sees it.
Below it, print how many letters are still hidden.
Start programming for free
1/3