A tablet showing an online course learning interface
A tablet on a desk showing an online course interface with video lessons.
2023 Application

Overview

The Wonder Learning catalog with six course cards, category filter buttons and a search box
The catalog: six courses, category filters, search, and a progress bar on each card.

Wonder Learning is a front-end e-learning platform: a course catalog, a course page with a video player and a lesson list, progress tracking, and a short quiz at the end of each course. It needs no backend. The whole catalog lives in one JavaScript data file, and each learner's progress is saved in their own browser.

It ships with 6 courses and 20 lessons in web development, Python, computer science, neural networks, Git, and Linux and containers. Every lesson is a public YouTube video by a well-known creator (Traversy Media, Fireship, CrashCourse, 3Blue1Brown, Programming with Mosh and freeCodeCamp), credited on the course page. All 20 video IDs were checked against YouTube's oEmbed service before they went into the catalog.

A lesson is marked done when its video ends, or by hand. The playback position is saved every five seconds, so a lesson reopens where you stopped, and the catalog offers a Continue link to the first unfinished course. When every lesson in a course is done, a three-question knowledge check unlocks and the best score is kept.

The source code is on GitHub at TYFSADIK/wonder-learning. The project dates from 2023; the code was rebuilt and published in 2026 with resume, quizzes, search and a test suite.

Features

FeatureHow it works
Data-driven catalogCards render from course-data.js; adding a course is a data edit
Category filter and searchFilter buttons with aria-pressed; search covers titles, descriptions, lesson titles and authors; both kept in the URL
Video lessonsYouTube iframe API; clicking a lesson switches video without reloading
Automatic completiononStateChange with ENDED marks the lesson done
Manual completionMark as done, or not done, with one button
Resume playbackPosition saved every 5 s while playing, and on leaving the page
Continue linkThe catalog points to the next lesson of the first started course
Knowledge check3 questions per course, unlocked at 100%; right and wrong answers outlined; best score saved
FallbackIf the YouTube API cannot load, a direct link to the video appears
ResetClears one course's progress after a confirmation

Architecture

Wonder Learning module structureTwo pages share one data file and one progress module. The catalog page renders cards with filters and search; the course page runs the YouTube player, completion, resume and the quiz. Progress lives in localStorage under one key.index.htmlcatalog pagecatalog.jscards, category filter, search, continue linkcourse.htmlcourse pageplayer.jslesson list, YouTube player, resume, quizYouTube iframe APIYT.Player, onStateChangecourse-data.js6 courses, 20 lessons, 18 quizquestionsprogress.jsgetProgress, setComplete, saveResume, saveQuiz, filterCourseslocalStoragekey wl-progresspostMessageimportJSON
Two pages, one data file, one progress module, one localStorage key. Both page scripts import the course data.

The pure logic sits in progress.js: reading and writing progress, percentages, quiz scoring and the catalog filter. It takes its storage as a parameter, so the tests hand it an in-memory object and the browser hands it localStorage. Everything that touches the page lives in catalog.js and player.js, and builds elements with createElement and textContent rather than HTML strings.

Tech Stack

  • Vanilla JavaScript (ES modules), two page scripts, one data module, one logic module
  • YouTube iframe API, YT.Player, loadVideoById, cueVideoById, getCurrentTime and onStateChange
  • localStorage, progress under one key as JSON, read inside try/catch
  • HTML5, semantic pages, a labelled progress bar, quiz questions as fieldset and legend
  • CSS3, a Grid catalog, a two-column course layout that stacks on phones, light and dark themes
  • Node test runner, 9 unit tests; Playwright for the end-to-end checks

Build Process

1
Model the catalog as data

A course is an object with an ID, a category, a level, a description, its lessons and its quiz. Lesson IDs follow the pattern courseId-lN, and a test enforces it.

{
  id: 'ml-101',
  title: 'Neural Networks, Visually',
  category: 'ai',
  level: 'Intermediate',
  lessons: [
    { id: 'ml-101-l1', title: 'What is a neural network?', videoId: 'aircAruvnKk', author: '3Blue1Brown' },
    { id: 'ml-101-l2', title: 'Gradient descent', videoId: 'IHZwWFHWa-w', author: '3Blue1Brown' },
    { id: 'ml-101-l3', title: 'Backpropagation, intuitively', videoId: 'Ilg3gGewQ5U', author: '3Blue1Brown' },
  ],
  quiz: [
    { q: 'What does gradient descent try to make smaller?',
      options: ['The number of layers', 'The cost function', 'The learning rate'], answer: 1 },
  ],
}
2
Design the storage schema first

All progress lives under one key, one entry per course. A flat list of lesson IDs would make per-course percentages depend on the ID format; a nested object keeps each course independent and makes reset a single delete.

// localStorage['wl-progress']
{
  "git-101": {
    "done": ["git-101-l1", "git-101-l2"],
    "quiz": 3,
    "resume": { "git-101-l2": 312 }
  }
}
3
Make storage failure harmless

localStorage can be full, blocked in private mode, or hold old or corrupt data. Reads are parsed inside try/catch, writes are wrapped too, and an older save format (a plain array) is upgraded on read. The storage object is injected, so the tests can make it throw on purpose.

export function createProgress(storage = globalThis.localStorage) {
  function loadAll() {
    try {
      const data = JSON.parse(storage.getItem(STORAGE_KEY));
      return data && typeof data === 'object' ? data : {};
    } catch {
      return {};
    }
  }
  function save(all) {
    try {
      storage.setItem(STORAGE_KEY, JSON.stringify(all));
    } catch {
      // Private mode or full storage: progress just will not persist.
    }
  }
  // ...
}
4
Render without HTML strings

Cards and lesson buttons are built with a tiny el() helper over createElement, so course text can never be interpreted as markup.

function el(tag, props = {}, ...children) {
  const node = Object.assign(document.createElement(tag), props);
  node.append(...children);
  return node;
}
5
Drive the YouTube player

The page loads the iframe API, creates the player in onYouTubeIframeAPIReady at the saved position, and listens to state changes. While a video plays, the position is saved every five seconds; within ten seconds of the end it counts as finished, so a lesson never resumes into the credits.

function onStateChange(e) {
  const { PLAYING, ENDED } = window.YT.PlayerState;
  clearInterval(resumeTimer);
  if (e.data === PLAYING) resumeTimer = setInterval(saveResume, 5000);
  else saveResume();
  if (e.data === ENDED) {
    setDone(current, true);
    const next = course.lessons[indexOf(current) + 1];
    if (next) $('next').focus();
  }
}
6
Filter and search

The catalog filter is a pure function: a category plus every word of the query must appear somewhere in the course text, including lesson titles and authors. So 3blue1brown gradient finds the neural networks course.

export function filterCourses(courses, { category = 'all', query = '' } = {}) {
  const q = query.trim().toLowerCase();
  return courses.filter(c => {
    if (category !== 'all' && c.category !== category) return false;
    if (!q) return true;
    const text = [c.title, c.description, ...c.lessons.map(l => `${l.title} ${l.author}`)].join(' ').toLowerCase();
    return q.split(/\s+/).every(word => text.includes(word));
  });
}
7
Gate the quiz on completion

The quiz form is only built once every lesson is done. Answers are radio buttons marked required, so the browser itself refuses an incomplete submission. Scoring is a pure function, and each question's fieldset is outlined green or red.

Learner Journey

A learner's path through a coursePick a course from the catalog, watch each lesson (it is marked done when the video ends, or by hand), come back later to the saved position, then take the quiz once every lesson is done.Catalogfilter by category, searchCourse pagefirst unfinished lesson opensWatch a lessonposition saved every 5 sVideo endslesson marked doneNext lessonor pick any from the listAll lessons donequiz unlocksKnowledge check3 questions, right and wrongmarkedCourse completebest score shown on thecataloglast lesson
From the catalog to a completed course.

The course page always opens on something useful: the lesson named in the URL if there is one, otherwise the first unfinished lesson. Every lesson switch updates the URL, so a link such as course.html?id=git-101&lesson=git-101-l2 opens that exact lesson.

The YouTube Player

Talking to the YouTube playerplayer.js loads the iframe API, creates the player when it is ready, saves the playback position while the video plays, and marks the lesson done when the video ends.player.jsiframe APIYouTube playerprogress.js1. load https://www.youtube.com/iframe_api2. onYouTubeIframeAPIReady()3. new YT.Player(videoId, start: saved seconds)4. onReady: hide the fallback link5. onStateChange: PLAYING6. every 5 s: saveResume(lesson, getCurrentTime())7. onStateChange: ENDED8. setComplete(lesson); clear the resume pointIf the API never loads within 8 s, a direct Watch on YouTube link appears
Events flow from the player to the page; the page writes progress.

One development trap deserves a note: the iframe API talks to the page with postMessage, and from a file:// page the origin is null, so the callbacks never arrive. The project must be served over HTTP, even locally, and the README says so first.

Testing

Wonder Learning on a phone in dark mode, with the video player above the lesson list
On a phone, in dark mode: the player goes first and the lesson list follows.

Nine unit tests run in Node with no browser, because the logic module takes its storage as an argument:

  • Completion is stored per course and never duplicated, and a lesson can be marked not done again
  • Corrupt JSON and the older array format both load without crashing
  • Storage that throws on every call (private mode) is tolerated
  • Resume points are kept after five seconds and cleared at zero
  • The quiz keeps the best score, and scoring and percentages are right
  • Filtering by category and by several search words, together and apart
  • The catalog data itself: unique IDs, the lesson ID pattern, 11-character video IDs, an author on every lesson, and quiz answers that point at a real option

Then 16 end-to-end checks ran in Chrome with Playwright: filters, search and its URL, the YouTube player actually loading, completion percentages, quiz locking, the browser refusing an incomplete quiz, scoring, persistence across a reload, the completed course on the catalog, the not-found page, and no sideways scrolling on a phone.

The one feature that needs a real video was tested with a real video: the test drove the embedded player through the public API to the last seconds of the 117-second Git in 100 seconds lesson, let it end, and confirmed that the lesson was marked done on its own.

Challenges and Lessons Learned

Third-party APIs need a real origin. The YouTube API failing silently from file:// looks exactly like a bug in your own code. Reproduce integrations over HTTP from the first day.

Browser storage is a database; give it a schema. Choosing the nested { courseId: { done, quiz, resume } } shape early kept every query simple, and an explicit upgrade path for the old format kept existing progress.

Plan for storage to fail. Private browsing and full quotas make localStorage throw. Wrapping reads and writes means the site still works; it just forgets.

Placeholder data ships. The original draft of the catalog had a PASTE_YOUTUBE_ID_HERE placeholder. Checking every ID against oEmbed before release is cheap, and it caught one dead ID before it reached the catalog.

Test with the real thing where it matters. Mocking the YouTube player would have proved nothing about the ENDED event. Letting a real video finish proved it works.

What I Learned

  • The YouTube iframe API lifecycle: loading, onYouTubeIframeAPIReady, player events and playback control
  • Designing a localStorage schema, and making reads and writes fail safely
  • Dependency injection in plain JavaScript: passing storage in makes browser code testable in Node
  • Data-driven rendering, the idea behind component frameworks, built by hand
  • Accessible controls without a framework: real buttons, aria-pressed, aria-current, labelled progress bars and fieldsets
  • URL state with URLSearchParams and history.replaceState

What You Need

CategoryItemNotes
ToolA local web server, e.g. npx serveRequired: the YouTube API does not work from file://
ToolA modern browserlocalStorage and ES modules
ToolNode.js 20 or laterOnly for the unit tests
ContentPublic YouTube videosCheck each ID before adding it
SkillJavaScript modules and the DOMNo framework
SkillBasic accessibilityButtons, labels, focus, ARIA states

What Is Next

  • Optional sign-in with a small backend (or Supabase) to sync progress across devices
  • Lesson notes and bookmarks at a timestamp
  • Longer quizzes with explanations for each answer
  • Search inside video transcripts
  • An offline catalog with a service worker
  • Publishing a live demo on GitHub Pages
JavaScript ES Modules YouTube iframe API localStorage E-Learning Accessibility Unit Testing