Task model
- Node.js course
- Beginner
- Lesson 83/116
- 6 min
Design the Task object and array structure.
Task model
In this 5-lesson project you will build a to-do list application. Each lesson adds one piece; the final lesson gives you a complete command-line application.
The first lesson designs the task object. A task will have two fields: title (the title text) and done (whether it is done). This shape is used in every lesson of the project. In JavaScript you group related data under a single object with the literal { }.
Example: const task = { title: 'Ekmek al', done: false }. This represents a task titled 'Ekmek al' that is not yet done. You can read the title with task.title.
Define a task with an object
A task object is defined with an object literal: { title: '...', done: false }. title is a string, done is a boolean. A new task always starts with false (not done).
After binding the object to a const variable, you can reach its fields with dot notation: task.title gives the title, task.done gives the status. You can change a field later: task.done = true marks the task as done.
In this lesson you will define a single task object and print its title. In later lessons we will gather these objects into an array.
Practice Print the task object
Define a task object: { title: 'Ekmek al', done: false }. Print the task.title property with console.log.
Starter code
// Define a task object and print its titleSample solution
const task = { title: 'Ekmek al', done: false };
console.log(task.title);Expected output
Ekmek al
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does task.title print?
const task = { title: 'Ekmek al', done: false };
console.log(task.title);- Task
- null
- Ekmek al Correct answer
- Empty
Explanation: the task.title property holds 'Ekmek al'.
2 The done field
const task = { title: 'Ekmek al', done: ____ };
const task = { title: 'Ekmek al', done: false };
Explanation: done: false means the new task is not done.
3 Match the task object parts
| Term | Meaning |
|---|---|
title |
Title field |
done |
Status field |
false |
done value for a new task |
task.title |
Access to the title |