TalentJR

Lesson 15

Building a To-Do List App

Combine DOM and arrays into an app

1What is a To-Do List App?✨

A To-Do List App helps users organize tasks they need to complete. It allows adding, removing, and marking tasks as done, making it a great project to practice JavaScript with DOM and arrays!

2Why Build a To-Do List App?🎯

  • ✓ Hands-on experience with arrays and the DOM
  • ✓ Learn to manage user input and display updates
  • ✓ Create a practical tool that can be used daily
  • ✓ Enhance your coding skills for real-world applications

3Creating the HTML Structure💡

Start by creating a simple HTML layout for your app. You'll need an input field to add tasks, a button to submit, and a list to display them.

4```html🚀

💻 code
<input type="text" id="taskInput" placeholder="Add a new task">
<button id="addTaskButton">Add Task</button>
<ul id="taskList"></ul>
```

5Using Arrays to Manage Tasks🔍

In JavaScript, use an array to store your tasks. Each time a new task is added, push it into the array and update the displayed list.

6```javascript⭐

💻 code
let tasks = [];
💻 code
function addTask(task) {
    tasks.push(task);
    displayTasks();
}
```

7Updating the DOM🧩

To show the tasks on the screen, you'll need to update the DOM. Create a function that clears the current list and repopulates it with tasks from the array.

8```javascript🎈

💻 code
function displayTasks() {
    const taskList = document.getElementById('taskList');
    taskList.innerHTML = '';
    tasks.forEach(task => {
        const li = document.createElement('li');
        li.textContent = task;
        taskList.appendChild(li);
    });
}
```

9Handling User Input✨

Add an event listener to the button so that when it's clicked, the task from the input field is added to the array. Make sure to clear the input field after adding the task.

10```javascript🎯

💻 code
document.getElementById('addTaskButton').addEventListener('click', () => {
    const input = document.getElementById('taskInput');
    const task = input.value;
    if (task) {
        addTask(task);
        input.value = '';
    }
});
```

11Final Touches💡

Consider adding features like removing tasks or marking them as completed. This will enhance your app and give you a deeper understanding of JavaScript and the DOM.

  • ✓ You've built a functional To-Do List App!
  • ✓ Keep experimenting with new features and designs.
  • ✓ Practice makes perfect, so don’t hesitate to try new ideas!

🎯 Practice Challenges

Master Building a To-Do List App by completing all 3 difficulty levels

🟢 EASY

Building a To-Do List App - Easy Challenge

Start with the basics. Perfect for beginners!

🟡 MEDIUM

Building a To-Do List App - Medium Challenge

Get more challenging. Build your confidence!

🔴 HARD

Building a To-Do List App - Hard Challenge

Master this concept. Prove your skills!

🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →

Ready to Master Building a To-Do List App? 🚀

Complete the challenges, take the quiz and keep your learning streak going!