Blog / Build with AI /

Building a typing speed test with AI

A typing speed test is a perfect small project. It has one screen, a clear job, instant feedback and a bit of fun. It also teaches three things that matter in almost every web build: timers, comparing input with expected text and doing a little maths.

The finished thing: a single HTML page that shows a sentence, starts a timer when you begin typing, and shows your words per minute and accuracy when you finish.

If you have not built anything with AI yet, choosing your first AI project explains why small projects like this teach more than ambitious ones.

Step 1: write down what “done” means

Before you prompt, decide:

  • It shows one sentence to type.
  • The timer starts on the first key press.
  • When the typed text matches the sentence length, it stops.
  • It shows words per minute (WPM) and accuracy.
  • There is a Restart button.
  • No libraries, no saving, no login.

Writing this takes two minutes and stops the assistant adding a leaderboard you did not ask for.

Step 2: the prompt

Build a typing speed test as a single HTML file with inline CSS and JavaScript, no libraries. Show a sentence from a list of five. Below it, a text box. The timer starts on the first key press and stops when the typed text reaches the sentence length. Show words per minute and accuracy as a percentage, plus a Restart button that picks a new sentence. Keep the design clean, readable on mobile, and comment each section of the code.

Paste the output into a file called typing.html, save it and open it in your browser.

Step 3: understand the maths

Do not skip this bit; it is where an AI can be subtly wrong.

The usual definition of WPM treats five characters as one “word”. So:

  • Words = characters typed ÷ 5
  • Minutes = seconds elapsed ÷ 60
  • WPM = words ÷ minutes

If you typed 200 characters in 60 seconds, that is 40 words in one minute: 40 WPM.

Accuracy is the share of characters that matched the target:

  • Accuracy = correct characters ÷ total characters typed × 100

Here is a short version of the key function, so you can recognise it when the assistant writes it:

function results(typed, target, seconds) {
  let correct = 0;
  for (let i = 0; i < typed.length; i++) {
    if (typed[i] === target[i]) correct++;
  }
  const wpm = Math.round((typed.length / 5) / (seconds / 60));
  const accuracy = Math.round((correct / typed.length) * 100);
  return { wpm, accuracy };
}

If your version divides by something odd or counts words by splitting on spaces, ask why. Both methods exist, but you should know which one you are using.

Step 4: test it properly

Typing tests have a few classic bugs. Try each one:

  1. Empty input. Press Restart without typing. Does it show “NaN” or divide by zero?
  2. Very fast typing. Paste the sentence in. Does it report an absurd speed? A good tool might block pasting.
  3. Backspace. Delete a few letters. Does accuracy handle it sensibly?
  4. Extra characters. Type past the end. Does it stop cleanly?
  5. Restart mid-test. Does the timer reset, or does the old one keep running?
  6. Phone. Type on your phone keyboard. Autocorrect and predictive text can change what appears.

You will probably find at least two. Fix them one at a time, in separate requests. Iterating with AI: small changes beat big rewrites explains why.

A prompt for the fixes:

The result shows NaN if I click Restart before typing. Fix only that. Show me the changed lines, not the whole file.

Step 5: small upgrades

When the base works, add one thing at a time:

  • Different lengths: 15, 30 or 60 seconds instead of a fixed sentence.
  • Highlighting: green for correct characters, red for wrong ones as you type.
  • A personal best, saved in the browser using local storage.
  • Random text from a longer word list.
  • A difficulty option with punctuation and capitals.

Each is a good prompt on its own. The personal best is a useful lesson in saving a small amount of data in the browser, and it is also the point where you should ask the assistant what is being stored and where.

What the project teaches

  • Events. Reacting to key presses.
  • State. Knowing whether a test is waiting, running or finished.
  • Time. Measuring how long something took.
  • Edge cases. What happens when users do unexpected things.

State is the big one. Many beginner bugs come from the page not knowing what mode it is in. If you can say “waiting, running, finished” out loud, you can ask the assistant for a cleaner structure.

Putting it online

A single file can go on free static hosting in minutes. Before you share it:

  • Give it a clear title and a short description in the page head.
  • Make sure text is large and has enough contrast, which accessibility checks for small tools covers.
  • Test on at least one phone and one desktop browser.

If you run a site already, a typing test also makes a harmless, shareable page that shows how to ship something small.

Key takeaways

  • A typing test is a compact way to learn timers, input handling and simple maths.
  • Define “done” first, then give the assistant tight constraints.
  • Know your formulas: characters divided by five gives words; words per minute needs elapsed time in minutes.
  • Test empty input, pasting, backspace, going past the end and restarting mid-test.
  • Add upgrades one at a time.

What would you add first: a timer length option, colour highlighting or a personal best?