@@ -2,9 +2,11 @@ const taskInput = document.querySelector("#taskInput");
2
2
const taskAddBtn = document . querySelector ( "#addSvg" ) ;
3
3
const taskContainer = document . querySelector ( ".task-container" ) ;
4
4
const taskField = document . querySelector ( ".task" ) ;
5
+ const taskCountText = document . querySelector ( "#clearAllTaskText" ) ;
5
6
const clearAllTaskBtn = document . querySelector ( "#clearAllTaskBtn" ) ;
6
7
const taskCompletedIcon = "fa-solid fa-circle-check pendingSvg" ;
7
8
const taskUncompletedIcon = "fa-regular fa-circle pendingSvg" ;
9
+ let taskCount = 3 ;
8
10
9
11
const completedTask = ( task ) => {
10
12
@@ -22,13 +24,21 @@ const completedTask = (task) => {
22
24
const shiftTask = task . cloneNode ( true ) ;
23
25
task . remove ( ) ;
24
26
taskContainer . append ( shiftTask ) ;
27
+
28
+ // update task counts
29
+ taskCount -- ;
30
+ updateTaskCount ( ) ;
25
31
}
26
32
else
27
33
{
28
34
// update icon, enable edit
29
35
uncheckIcon . className = taskUncompletedIcon ;
30
36
editIcon . style . display = "block" ;
31
37
task . classList . remove ( "checked" ) ;
38
+
39
+ // update task counts
40
+ taskCount ++ ;
41
+ updateTaskCount ( ) ;
32
42
}
33
43
}
34
44
@@ -42,7 +52,12 @@ const editTaskText = (task) => {
42
52
43
53
// delete the task when clicked on deleteIcon
44
54
const deleteTask = ( task ) => {
55
+ // remove the task from the list
45
56
task . remove ( ) ;
57
+
58
+ // update task counts
59
+ taskCount -- ;
60
+ updateTaskCount ( ) ;
46
61
} ;
47
62
48
63
const addNewTask = ( ) => {
@@ -60,6 +75,10 @@ const addNewTask = () => {
60
75
// append the task and empty the inputBox value
61
76
taskContainer . append ( newTaskField ) ;
62
77
taskInput . value = '' ;
78
+
79
+ // update task counts
80
+ taskCount ++ ;
81
+ updateTaskCount ( ) ;
63
82
}
64
83
else
65
84
alert ( "Task must be of at least 5 characters to be registered." ) ;
@@ -108,12 +127,23 @@ taskContainer.addEventListener("click", (e) => {
108
127
}
109
128
} ) ;
110
129
130
+ const updateTaskCount = ( ) => {
131
+ if ( taskCount === 0 )
132
+ taskCountText . textContent = `Mission Accomplished!` ;
133
+ else
134
+ taskCountText . textContent = `You have ${ taskCount } pending tasks` ;
135
+ }
136
+
111
137
// remove all childs of "taskContainer" class
112
138
clearAllTaskBtn . addEventListener ( "click" , ( ) => {
113
139
114
140
// ask for confirmation
115
141
if ( confirm ( "All the tasks will be cleared permanently." ) )
116
142
{
117
143
taskContainer . setHTML ( '' ) ;
144
+
145
+ // update task counts
146
+ taskCount = 0 ;
147
+ updateTaskCount ( ) ;
118
148
}
119
149
} ) ;
0 commit comments