1- // Store everything imported from './todos.mjs' module as properties of an object named Todos
1+ // Store everything imported from './todos.mjs' module as properties of an object named Todos
22import * as Todos from "./todos.mjs" ;
33
44// To store the todo tasks
@@ -9,14 +9,13 @@ window.addEventListener("load", () => {
99 document . getElementById ( "add-task-btn" ) . addEventListener ( "click" , addNewTodo ) ;
1010
1111 // Populate sample data
12- Todos . addTask ( todos , "Wash the dishes" , false ) ;
12+ Todos . addTask ( todos , "Wash the dishes" , false ) ;
1313 Todos . addTask ( todos , "Do the shopping" , true ) ;
1414
1515 render ( ) ;
1616} ) ;
1717
18-
19- // A callback that reads the task description from an input field and
18+ // A callback that reads the task description from an input field and
2019// append a new task to the todo list.
2120function addNewTodo ( ) {
2221 const taskInput = document . getElementById ( "new-task-input" ) ;
@@ -45,12 +44,11 @@ function render() {
4544 } ) ;
4645}
4746
48-
4947// Note:
5048// - First child of #todo-item-template is a <li> element.
5149// We will create each ToDo list item as a clone of this node.
5250// - This variable is declared here to be close to the only function that uses it.
53- const todoListItemTemplate =
51+ const todoListItemTemplate =
5452 document . getElementById ( "todo-item-template" ) . content . firstElementChild ;
5553
5654// Create a <li> element for the given todo task
@@ -62,15 +60,24 @@ function createListItem(todo, index) {
6260 li . classList . add ( "completed" ) ;
6361 }
6462
65- li . querySelector ( ' .complete-btn' ) . addEventListener ( "click" , ( ) => {
63+ li . querySelector ( " .complete-btn" ) . addEventListener ( "click" , ( ) => {
6664 Todos . toggleCompletedOnTask ( todos , index ) ;
6765 render ( ) ;
6866 } ) ;
69-
70- li . querySelector ( ' .delete-btn' ) . addEventListener ( "click" , ( ) => {
67+
68+ li . querySelector ( " .delete-btn" ) . addEventListener ( "click" , ( ) => {
7169 Todos . deleteTask ( todos , index ) ;
7270 render ( ) ;
7371 } ) ;
7472
7573 return li ;
76- }
74+ }
75+
76+ // 4. In `script.js`, call `deleteCompleted()` whenever the new button is clicked.
77+ // - ⚠️ You should not need to modify the `render()` function.
78+ document
79+ . getElementById ( "delete-completed-btn" )
80+ . addEventListener ( "click" , ( ) => {
81+ Todos . deleteCompleted ( todos ) ;
82+ render ( ) ;
83+ } ) ;
0 commit comments