Command Palette

Search for a command to run...

Hectal
Phase 4: State and Events
React · Exercise 5 of 5 Previous
Intermediate

Mini build: a to-do list with done, delete and clear

Build a to-do list that starts with two to-dos: Learn events (done) and Learn state (not done).

Each to-do is an <li> in <ul id="todos"> with its text in <span className="text">, a button with className="toggle" that flips done/not done, and a button with className="delete". A done <li> has the class done.

A form with input id="new-todo" adds a to-do (not done) at the end and empties the input; empty text adds nothing. A paragraph id="left" shows how many are not done, like 1 left. A button id="clear" removes every done to-do.

Store the to-dos as one array of objects { id, text, done } and never mutate it or its objects. Work out the left count during render instead of storing it.

What Check tests

  1. It starts with two to-dos, Learn events marked done, and 1 left
  2. Adding Learn hooks puts it at the end, empties the input and shows 2 left
  3. Empty text adds nothing
  4. Toggling Learn state marks it done and shows 1 left
  5. Clear done removes both done to-dos
  6. Delete removes the last to-do and shows 0 left
  7. No mutation: no push, splice or .done = in the code

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.