Project: To-do list
Overview of the 5-lesson to-do project: manage tasks as objects.
To-do list project
In this project you will build a to-do list application across five lessons. Each task is stored as an object and kept in an array.
The app will support adding, listing, completing and deleting tasks. Each lesson adds one piece and builds on the previous lesson's solution. You will start by defining an empty list and a counter.
Project structure
The app manages four core operations. addTask adds a new task, listTasks shows all of them, completeTask finishes one and deleteTask removes it.
Each task carries three fields: id (a unique number), title (the task name) and completed (is it done). The id values come from a nextId counter that increases with every addition.
How we store the data
We keep the tasks in an array. At first the array is empty: let tasks = []. Each new task is added to this array with push.
Every task needs a unique number. The nextId variable starts at 1 for the first task and grows after each addition. This way two tasks never share the same id.
Exercise Initialize the task list
Define an empty tasks array and a nextId counter set to 1. These two will be the base for the rest of the project.
Show example solution
Start the array with [] and the counter with 1.
Example solution:
let tasks = [];
let nextId = 1;
Test yourself
-
Which field tracks the completion state of a task?
- id
- title
- completed
- nextId
Show answer
completed — The completed field holds true or false and tells whether the task is finished.
-
Define the task list array
// Task list let ____ = [];Show answer
// Task list let tasks = [];