Build Hangman

In this module, you will build a hangman game that runs in the browser: a page where you type a letter, click Guess, and watch the board update. You start with a playable game in the first problem and add features from there.

But there is a twist: you write both the code and the tests.

The platform checks that your code is correct, and that your tests are meaningful. After each step, you will see which common mistakes your tests would catch and which ones they would miss.

This is not about following a rigid “write tests first” process. Sometimes you will write the function first and then add tests. Sometimes a test will help you think through the logic before you code. The skill is learning to use tests as a thinking tool to clarify your intent, catch your own mistakes, and build confidence in your code.


What you will build

By the end, your functions will power a page like this:

+------------------------------------------+
|                                          |
|  p _ _ _ _                               |
|  Guesses remaining: 6                    |
|  Score: 30                               |
|  Available: abcdefghijklmnoqrstuvwxyz    |
|                                          |
|  +----------------------------+ +-----+  |
|  |                            | |Guess|  |
|  +----------------------------+ +-----+  |
|                                          |
|  Nice!                                   |
|                                          |
+------------------------------------------+
  • The game board: displaying the word, handling guesses, detecting win and loss
  • Validation: rejecting bad input, preventing duplicate guesses
  • Choosing a word: testing random code, separating concerns
  • Scoring: calculating results, composing everything into a final turn
  • Pattern matching (optional): an algorithmic challenge

Each problem builds on the last. Each step includes a read-only HTML file showing how your function plugs into the page. Within a problem, you carry your own code forward. At problem boundaries, you get clean implementations of prior functions so you can focus on the new skill.

01

The Game Board

beginner
0/3
02

Validation

beginner
0/2
03

Choosing a Word

beginner
0/4
04

Scoring and Integration

intermediate
0/2
05

Pattern Matching Hints

advanced
0/2