Project: My Tasks
No new theory: this project uses everything from the first seven parts. A form, a list built from an array of objects, localStorage with JSON, the focus, a live region, and a dark mode. You build your own page from an empty folder: a to-do list that remembers your tasks.
This project is separate from the station site. When you're not sure how to do a step, open the lesson it comes from again.
Your files
The folder starts empty. Make three files with New file: index.html, style.css and script.js.
What you will see
You will use this list every day, on your computer and on your phone, in the morning and late at night. You type a task and add it. You tick it when it's done, delete it, or clear all the done tasks at once. The list remembers your tasks when you come back.
The steps
Build it in this order:
- The frame. An English page that can show any letter and is made for the width of a phone, with one sentence about the list for search engines. It's called My Tasks on its tab and in its only biggest heading.
- The parts. A form with the id
task-formholds a box with the idtask-input, with its label, and a button that sends the form. Under the form: an empty list with the idtask-list, a paragraph with the idtask-count, read out loud politely when it changes, and a button with the idclear-done. - Adding a task. The head loads
script.js, which waits for the page. It keeps the tasks in an array of objects, each one with its text and whether it's done. Sending the form adds a task at the end of the list, without sending the form anywhere. Then the box is empty again, and the focus is in it, ready for the next task. An empty box, or one with only spaces, adds nothing. - What a task shows. Each task of the list is an
liwith, in this order: a box to tick, its text in aspanwith the classtask-text, and a button with the classdelete. The page draws the whole list again from the array after every change. - Done. Ticking a task's box marks it done: its
ligets the classdone, and its text has a line through it. Unticking it brings it back. - Delete. A task's delete button removes that task, and only that one.
- What's left.
#task-countsays how many tasks are not done yet:2 tasks left,1 task left, orNothing left to do. - Remembered. After every change, the tasks are saved in the browser as JSON, under the key
tasks. When the page opens, it shows the saved tasks, done or not. - Clean up. A click on
#clear-doneremoves every done task, and saves. - Day and night. The page's colors are custom properties. It's light by default, and dark when the device asks for dark mode. Its text is always easy to read, with a contrast of at least 4.5.
- On a phone. The list stays in one column that is easy to read, at most 600 pixels wide on a computer. Nothing comes out sideways on a phone, even with a long task.
The tests also try your page with tasks saved on an earlier visit. So read them from the browser with the key and the shape given in the steps.
Run the tests when you like. They tell you which steps are still missing.