File tree Expand file tree Collapse file tree 3 files changed +28
-8
lines changed
Expand file tree Collapse file tree 3 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ const deleteBtn = document.querySelectorAll('.del')
22const todoItem = document . querySelectorAll ( 'span.not' )
33const todoComplete = document . querySelectorAll ( 'span.completed' )
44const editBtns = document . querySelectorAll ( 'span.edit' ) ;
5+ const completedTasks = document . getElementById ( 'completedTasks' ) ; // Get the completed tasks element
56
6- Array . from ( deleteBtn ) . forEach ( ( el ) => {
7+ Array . from ( deleteBtn ) . forEach ( ( el ) => {
78 el . addEventListener ( 'click' , deleteTodo )
89} )
910
@@ -111,4 +112,19 @@ async function editTodo() {
111112 input . addEventListener ( 'keydown' , ( e ) => {
112113 if ( e . key === 'Enter' ) saveEdit ( ) ;
113114 } ) ;
114- }
115+ }
116+
117+ // Update message when all todos are completed
118+ function updateMessage ( ) {
119+ const todos = document . querySelectorAll ( 'span.not, span.completed' ) ;
120+ const completed = document . querySelectorAll ( 'span.completed' ) ;
121+ const total = todos . length ;
122+ const done = completed . length ;
123+
124+ if ( done === total && total > 0 ) {
125+ completedTasks . style . display = 'block' ;
126+ } else {
127+ completedTasks . style . display = 'none' ;
128+ }
129+ }
130+ updateMessage ( ) ;
Original file line number Diff line number Diff line change 2121
2222 <h2 ><%= user .userName %> has <%= left %> things left to do.</h2 >
2323
24+ <!-- Show message when all todos are completed -->
25+ <h3 id =' completedTasks' style =' display :none ;' >🎉Congratulations <%= user .userName %> ! You have completed your tasks today!</h3 >
26+
2427 <form action =" /todos/createTodo" method =' POST' >
2528 <input type =" text" placeholder =" Enter Todo Item" name =' todoItem' >
2629 <input type =" submit" >
You can’t perform that action at this time.
0 commit comments