Back to docsRecipe

Recipe: Quiz generator from a source doc

Build a self-contained quiz engine that ingests a source document, extracts key facts, and generates multiple-choice questions with instant scoring — all running client-side.

1

Parse source

Accept plain text or markdown. Split into sentences, filter noise, extract noun-phrase candidates as answer targets.

2

Generate distractors

For each correct answer, pull plausible wrong options from adjacent sentences or a small embedded word list.

3

Score & review

Track per-question results, show a final score, and highlight missed answers with the source sentence for context.

Ingredients

  • Text splitter with sentence-boundary detection
  • Noun-phrase extractor (simple regex or compromise.js)
  • Distractor pool builder from local context
  • Fisher-Yates shuffle for answer ordering
  • React state machine: idle → quiz → results
  • Tailwind card layout with progress bar

Tip: Keep the distractor pool small (3–4 options per question). Use the source document's own vocabulary for wrong answers — they feel more natural than random words.