Now it's time to make your todo app truly powerful! Today you'll learn how to delete tasks, mark them as complete, and track statistics. We'll build on everything you learned in the previous lessons to create a fully functional todo application.
A basic todo app that only adds items isn't very useful in real life. People need to complete tasks, remove things they no longer need, and see their progress. These features make your app actually usable and show you're thinking like a real developer!
To build these advanced features, we'll use some powerful JavaScript concepts. Don't worry - we'll explain each one step by step!
todos.filter(todo => todo.id !== deleteId) removes the item with that ID.
todos.map(todo => todo.id === id ? {...todo, completed: !todo.completed} : todo)
{...todo, completed: true}
onclick="deleteTodo(${todo.id})". This lets each button know which item to
work with.
Your starter code has a basic todo app, but it's missing the most important features! You'll implement three key functions to make it fully functional.
Test each function as you complete it. Try adding a task, then toggle it, then delete it. Make sure the statistics update correctly!
completed status from true
to false or vice versa. Use array.map() and the spread operator to create a
new array with the updated todo.
array.filter() to
create a new array without that item. Remember to also update the display and stats!
Once you complete the basic functionality, try adding a "Clear Completed" button that removes all finished tasks at once!
What you're building today is the foundation of how most web applications work:
Your todos array is your "data" - it represents the current state of your
application. Every time you modify this data (add, toggle, delete), you update the UI to match.
This pattern is used in professional web development!
Your app responds to user events (clicks) by calling functions that modify data and update the display. This reactive approach makes your app feel responsive and modern.
In Lesson 10, we'll add data persistence so your todos survive page refreshes, and we'll polish the app with animations and better styling. You're building real developer skills!