Skip to content
FORGENO ADS GAMESUnlock all $8

JavaScript · Unit 3: Working with data · Lesson 6 of 6

Final project: to-do list logic

Your final JavaScript project is the logic behind a to-do list app: adding tasks, ticking them off and counting what is left.

Opens this lesson in Code Academy. Lessons open one after another, and each unit opens when you pass the checkpoint quiz before it (you can take a checkpoint early to skip ahead). If this lesson is not open yet, the button shows you its unit on your map.

The idea

Your final JavaScript project is the logic behind a to-do list app: adding tasks, ticking them off and counting what is left.

Each task is an object like { text: "Buy milk", done: false } and the list is an array of them. Each function takes the list and returns a result, without changing the original.

Two handy tools: [...list, item] makes a new array with one more item, and { ...task, done: true } makes a copy of an object with one key changed.

Worked example

JavaScript

const todos = [
  { text: "Buy milk", done: false },
  { text: "Walk the dog", done: true }
];
console.log(todos.length);
console.log(todos[1].text);
console.log(todos.filter((t) => !t.done).length);
const more = [...todos, { text: "Read", done: false }];
console.log(todos.length, more.length);

It prints

2
Walk the dog
1
2 3

Key terms

Object
Values grouped under named keys in { }. Read them with a dot: book.title.
Array
An ordered list in [ ]. Indexes start at 0; length counts the items; push adds one.
map and filter
map changes every item into a new array; filter keeps only the items that pass a test.

Practise it in Code Academy

This is a project lesson. It has 4 exercises (multiple choice and write code from a prompt) and takes about 15 minutes. Every answer is checked as you go, and feedback names the exact mistake. Hints and the solution are there if you get stuck.

Every lesson is free: no ads, no lives and no paywall.