Skip to content
Tutorials Center
My learning

Topics

Lesson 66 of 77 ยท Projects

Project: A Flashcard Trainer with Spaced Repetition

Build an interview flashcard trainer in JavaScript: a question bank, Leitner boxes, scoring and in-memory persistence, with every step runnable.

In the study plan lesson you saw how spaced repetition decides when to review a fact. Now you will build the real thing: a small flashcard trainer that stores a bank of interview questions, schedules reviews with Leitner boxes, scores your sessions and saves progress.

The project is a command-line style program in plain JavaScript. It has no framework and no storage service, because the aim is to practice the design: data model, scheduling logic, scoring and persistence, in small testable pieces. Each step runs in the editor and builds on the last.

What we will build

Question bank Cards with a topic and an answer.
Leitner boxes Right moves up, wrong drops to box 1.
Scoring Accuracy per topic and per session.
Persistence Save and load state as JSON.

Four small modules, one tiny app.

1 / 2

Step 1: model the question bank

A card needs an id, a topic, a question and an answer. It also needs scheduling state: which box it is in, the day it is next due, and how often you got it right or wrong. Keeping state inside the card object makes saving easy, because the whole deck is a plain array.

Use a factory function so every card starts in the same condition, and keep content (what the card says) separate from progress (how well you know it). That separation will let you update the question text later without losing history.

JS Step 1: cards and the bank

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Step 2: the Leitner scheduler

Leitner boxes are five buckets. Box 1 is reviewed every day, box 2 every 2 days, box 3 every 4, box 4 every 8 and box 5 every 16. A correct answer moves the card up one box; a wrong answer sends it back to box 1. The scheduler is a pair of pure functions: one that applies an answer to a card on a given day, and one that returns the cards due on that day.

Keeping them pure (no hidden clock, no random) is what makes them easy to test. The current day is always passed in as a number.

JS Step 2: grade a card and find what is due

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Sorting by box puts the weakest cards first, which is what you want when time is short. Notice that a card already due on a past day is still due today; you never lose overdue cards.

Step 3: run a session and score it

A session takes today's due cards and asks each one. In a real app a person types an answer or self-rates "knew it / missed it". Here a scripted learner stands in for you, so the output is deterministic: it knows every card except the ones listed for each day.

Scoring has two layers. Session accuracy is right answers divided by questions asked. Topic accuracy is the lifetime right-answer rate per topic, and it tells you where to study. This is the same weak-topic tracker described in the study-plan lesson.

JS Step 3: a scripted session with scoring

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Read the output as a story: on day 0 two cards were missed and stay in box 1, so they return on day 1, while the three correct cards moved to box 2 and are quiet until day 2. Operating-systems accuracy is the lowest because deadlock was missed twice.

Step 4: persistence

A trainer is only useful if progress survives. In a real browser you would call localStorage.setItem, in Node you would write a file, and on a server you would use a database. The sandbox here has no storage, so we keep the state in memory and show the important part, which is serialization: turning the deck into a string and back.

Two details matter. Store a version number so you can change the format later and migrate old saves. And validate on load: if the saved text is corrupt, start a fresh deck instead of crashing.

JS Step 4: save and load with validation

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Putting it together

The whole app is these four pieces plus a thin loop:

  1. Load the saved state, or build a fresh deck from the bank.
  2. Ask dueCards(deck, today).
  3. For each card, show the question, wait for the answer, call grade.
  4. Print the session score, save the state and advance the day.

Because grading and scheduling are pure functions, the same code could run behind a web page, a terminal or a chat bot. Only the input and storage layers would change.

Ideas to extend it

  • Add a new-cards-per-day limit so a big bank does not flood day one.
  • Let users self-rate with three levels: missed (back to box 1), hard (stay in the box) and easy (jump two boxes).
  • Show a forecast: how many cards are due each of the next seven days.
  • Import cards from a CSV or a Markdown list; guard against duplicate ids.
  • Add tags and filter a session to your weakest topic.
  • Write tests: grading from every box, the box-5 ceiling, and overdue cards.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In the Leitner system used here, what happens to a card after a wrong answer?

    A miss resets the card to box 1, which is reviewed every day, so you see it again soon.
  2. 2. Why are grade and dueCards written as pure functions that take the day as a parameter?

    Passing the day in removes hidden state, so a test can simulate weeks of reviews in a few lines.
  3. 3. Why include a version number in the saved JSON?

    A version field lets later releases recognise old data instead of misreading it.
  4. 4. What should the app do if the saved text is corrupt?

    Persistence code must expect bad input. Validating on load and falling back keeps the app usable.

Summary

  • A card holds content plus scheduling state, so the deck is plain, serializable data.
  • Leitner boxes: right answers climb to longer gaps, wrong ones return to box 1.
  • Pure scheduling functions that receive the current day are simple to test.
  • Topic accuracy reveals what to study; session accuracy shows how a day went.
  • Save with a version, validate on load, and fall back to a fresh deck.

Next: Project: A Mock Interview Runner.