JavaScript AcademyProfessional Engineering

Level 3 · Interactive Web Applications Project 21 of 60 Runs in the browser

Project 21: Interactive To-Do List

A to-do list rendered from state: add, complete and delete tasks with event delegation, filter them, and keep them in localStorage.

Level 3 covers the DOM, events, forms, state and storage, so you write both files: the logic file holds pure state functions and app.js renders the state and handles events. Storage in the website's preview is memory-only; the downloaded project uses your browser's real localStorage.

1 · The problem

A to-do list is the classic first interactive application because it needs every browser skill at once: rendering a list from data, handling events on items that do not exist yet, a form that rejects empty tasks, filters, and remembering the list between visits.

User stories

  • As a user, I want to add a task and tick it off.
  • As a user, I want to see only what is left to do.
  • As a user, I want my list to be there when I come back.

2 · Requirements

  • Keep the tasks in a state array; never read the page to find out what the tasks are.
  • Render the list from state, with a checkbox and a delete button per task, and a count of tasks left.
  • Add a task from a form, ignoring empty or whitespace-only text.
  • Complete and delete tasks with one delegated listener on the list.
  • Filter All, Active and Done with buttons that show which filter is on (aria-pressed).
  • Save to localStorage after every change and load on start, falling back to sample tasks when storage is empty or broken.

Acceptance criteria

  • The page starts with 3 sample tasks and '2 tasks left'.
  • Adding 'Buy stamps' shows 4 tasks and '3 tasks left'.
  • Clicking Done shows only completed tasks.
  • After a change, localStorage holds the list as JSON.

Architecture

LayerFileResponsibility
Pageindex.html + style.cssForm, filter buttons, list and count.
Statetodos.jsPure functions: add, toggle, remove, filter, count. Your work.
View and eventsapp.jsrender(), event listeners, save and load. Your work.

Flow: Event → state = addTodo / toggleTodo / removeTodo(state, …) → saveTodos(state) → render() from state and the current filter

Expected result

Interactive To-Do List: finished app
finished app

Screenshots are captured automatically from the solution by the browser test suite.

Build it: guided stages

Pick a stage, load its starter files, follow the steps, then run the app and the tests. Every stage is preserved separately, so loading one never overwrites another.

  1. Stage 1: State and rendering · Write the state functions and draw the list from state.
  2. Stage 2: Events · Add, tick and delete tasks with a form and delegated listeners.
  3. Stage 3: Filters and storage · Filter the list and keep it between visits.

Troubleshooting

Clicking a new task's checkbox does nothing.
Listeners added to each <li> are lost when render() rebuilds the list. Listen once on the <ul> and use event.target.
The page reloads when I press Add.
Call event.preventDefault() in the submit listener.
A task with < in it breaks the page.
Set textContent, not innerHTML.

Extension challenges

  1. Double-click a task to edit its text.
  2. Add a Clear completed button.
  3. Show the number of tasks per filter on the buttons.

Downloads

Browser projects open directly from index.html. Node.js unit tests: run node --test in the project folder.

AI development prompts

Context: I am building the academy's Interactive To-Do List. Task: explain why event delegation keeps working after render() rebuilds the list. Constraints: explain the idea and point to the line that matters; do not write the whole solution. Expected behaviour: I can finish the stage myself. Testing: suggest two inputs that would show whether my code is right.
Context: My Interactive To-Do List passes the visible tests. Task: check my render() and listeners for duplicated listeners or HTML injection. Constraints: do not rewrite my code; list issues in order of importance. Expected behaviour: I understand each issue and can fix it. Testing: give one test case per issue.
Context: I finished the Interactive To-Do List. Task: help me plan this extension: edit a task's text in place. Constraints: keep the logic file free of page code; existing tests must still pass. Expected behaviour: a short plan with the functions to add or change. Testing: describe the new tests I should write first.

Source

Repository folder: projects/project-21-interactive-to-do-list/ · view on GitHub