@@ -7,6 +7,9 @@ const clearAllTaskBtn = document.querySelector("#clearAllTaskBtn");
77const taskCompletedIcon = "fa-solid fa-circle-check pendingSvg" ;
88const taskUncompletedIcon = "fa-regular fa-circle pendingSvg" ;
99let taskCount = 3 ;
10+ const noTasksMessage = `<div class="completed">
11+ <p>Add a task to plan your day.</p>
12+ </div>` ;
1013
1114const completedTask = ( task ) => {
1215
@@ -127,11 +130,40 @@ taskContainer.addEventListener("click", (e) => {
127130 }
128131} ) ;
129132
133+ // update the count of pending tasks
130134const updateTaskCount = ( ) => {
135+
136+ // reset the taskCount
137+ if ( taskCount < 0 )
138+ taskCount = 0 ;
139+
140+ // check whether all tasks completed
131141 if ( taskCount === 0 )
132142 taskCountText . textContent = `Mission Accomplished!` ;
133143 else
134144 taskCountText . textContent = `You have ${ taskCount } pending tasks` ;
145+
146+ // check for no tasks in list
147+ if ( taskCount < 2 )
148+ updateNoTaskMessage ( ) ;
149+ }
150+
151+ // add the message when no tasks are listed
152+ const updateNoTaskMessage = ( ) => {
153+
154+ // if there's nothing in task-container, show the message
155+ if ( taskContainer . childElementCount === 0 )
156+ taskContainer . setHTML ( noTasksMessage ) ;
157+ else if ( taskCount === 1 )
158+ {
159+ try {
160+ const removeMessage = taskContainer . querySelector ( ".completed" ) ;
161+ removeMessage . remove ( ) ;
162+ }
163+ catch ( error ) {
164+ // do nothing :)
165+ }
166+ }
135167}
136168
137169// remove all childs of "taskContainer" class
@@ -145,5 +177,8 @@ clearAllTaskBtn.addEventListener("click", () => {
145177 // update task counts
146178 taskCount = 0 ;
147179 updateTaskCount ( ) ;
180+
181+ // focus the input box for typing
182+ taskInput . focus ( ) ;
148183 }
149184} ) ;
0 commit comments