@@ -7,28 +7,35 @@ const todos = [];
77// Set up tasks to be performed once on page load
88window . addEventListener ( "load" , ( ) => {
99 document . getElementById ( "add-task-btn" ) . addEventListener ( "click" , addNewTodo ) ;
10-
10+ document
11+ . getElementById ( "delete-completed-btn" )
12+ . addEventListener ( "click" , deleteCompletedTodos ) ;
1113 // Populate sample data
1214 Todos . addTask ( todos , "Wash the dishes" , false ) ;
1315 Todos . addTask ( todos , "Do the shopping" , true ) ;
1416
1517 render ( ) ;
1618} ) ;
1719
18-
20+ function deleteCompletedTodos ( ) {
21+ Todos . deleteCompleted ( todos ) ;
22+ render ( ) ;
23+ }
1924// A callback that reads the task description from an input field and
2025// append a new task to the todo list.
2126function addNewTodo ( ) {
2227 const taskInput = document . getElementById ( "new-task-input" ) ;
28+ const deadlineInput = document . getElementById ( "deadline-input" ) ;
2329 const task = taskInput . value . trim ( ) ;
30+ const deadline = deadlineInput . value ;
2431 if ( task ) {
25- Todos . addTask ( todos , task , false ) ;
32+ Todos . addTask ( todos , task , false , deadline ) ;
33+ console . log ( todos ) ;
2634 render ( ) ;
2735 }
28-
2936 taskInput . value = "" ;
37+ deadlineInput . value = "" ;
3038}
31-
3239// Note:
3340// - Store the reference to the <ul> element with id "todo-list" here
3441// to avoid querying the DOM repeatedly inside render().
@@ -45,7 +52,6 @@ function render() {
4552 } ) ;
4653}
4754
48-
4955// Note:
5056// - First child of #todo-item-template is a <li> element.
5157// We will create each ToDo list item as a clone of this node.
@@ -56,8 +62,13 @@ const todoListItemTemplate =
5662// Create a <li> element for the given todo task
5763function createListItem ( todo , index ) {
5864 const li = todoListItemTemplate . cloneNode ( true ) ; // true => Do a deep copy of the node
59-
60- li . querySelector ( ".description" ) . textContent = todo . task ;
65+ const description = li . querySelector ( ".description" ) ;
66+ if ( todo . deadline ) {
67+ description . textContent = `${ todo . task } - Deadline: ${ todo . deadline } ` ;
68+ }
69+ else {
70+ description . textContent = todo . task ;
71+ }
6172 if ( todo . completed ) {
6273 li . classList . add ( "completed" ) ;
6374 }
@@ -73,4 +84,4 @@ function createListItem(todo, index) {
7384 } ) ;
7485
7586 return li ;
76- }
87+ }
0 commit comments