Won or Lost?

The player starts with 6 lives, which are in a new constant, lives, and each mistake costs one of them. The player wins by revealing the whole word, and loses by running out of lives.

Finish the program with one more line: You won! if no letter of the word is hidden, You lost! The word was JAVASCRIPT. (with the secret word) if the player has no lives left, and otherwise how many lives they have left. In this game, the player has made 2 mistakes, so the output ends like this:

Wrong guesses: ["E", "O"]
Mistakes: 2
Lives left: 4

The exercise also plays other games: one in which the player guesses every letter of JAVASCRIPT, one with six wrong guesses, and one with only 2 lives.

That's the whole game. Your program goes through a word letter by letter, checks each guess against it, counts the mistakes and decides how the game ends, all with arrays, loops and conditions. In the next lesson, on functions, you'll learn to give a piece of code a name and use it again whenever you need it. Then one function could show the word after every guess, not just at the end.

Instructions

Print how the game ends, or how many lives the player has left.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

3/3