Skip to content

Commit dae9aec

Browse files
committed
Feat: count pending tasks and show them to user
1 parent 7cfc54e commit dae9aec

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

script.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const taskInput = document.querySelector("#taskInput");
22
const taskAddBtn = document.querySelector("#addSvg");
33
const taskContainer = document.querySelector(".task-container");
44
const taskField = document.querySelector(".task");
5+
const taskCountText = document.querySelector("#clearAllTaskText");
56
const clearAllTaskBtn = document.querySelector("#clearAllTaskBtn");
67
const taskCompletedIcon = "fa-solid fa-circle-check pendingSvg";
78
const taskUncompletedIcon = "fa-regular fa-circle pendingSvg";
9+
let taskCount = 3;
810

911
const completedTask = (task) => {
1012

@@ -22,13 +24,21 @@ const completedTask = (task) => {
2224
const shiftTask = task.cloneNode(true);
2325
task.remove();
2426
taskContainer.append(shiftTask);
27+
28+
// update task counts
29+
taskCount--;
30+
updateTaskCount();
2531
}
2632
else
2733
{
2834
// update icon, enable edit
2935
uncheckIcon.className = taskUncompletedIcon;
3036
editIcon.style.display = "block";
3137
task.classList.remove("checked");
38+
39+
// update task counts
40+
taskCount++;
41+
updateTaskCount();
3242
}
3343
}
3444

@@ -42,7 +52,12 @@ const editTaskText = (task) => {
4252

4353
// delete the task when clicked on deleteIcon
4454
const deleteTask = (task) => {
55+
// remove the task from the list
4556
task.remove();
57+
58+
// update task counts
59+
taskCount--;
60+
updateTaskCount();
4661
};
4762

4863
const addNewTask = () => {
@@ -60,6 +75,10 @@ const addNewTask = () => {
6075
// append the task and empty the inputBox value
6176
taskContainer.append(newTaskField);
6277
taskInput.value = '';
78+
79+
// update task counts
80+
taskCount++;
81+
updateTaskCount();
6382
}
6483
else
6584
alert("Task must be of at least 5 characters to be registered.");
@@ -108,12 +127,23 @@ taskContainer.addEventListener("click", (e) => {
108127
}
109128
});
110129

130+
const updateTaskCount = () => {
131+
if(taskCount === 0)
132+
taskCountText.textContent = `Mission Accomplished!`;
133+
else
134+
taskCountText.textContent = `You have ${taskCount} pending tasks`;
135+
}
136+
111137
// remove all childs of "taskContainer" class
112138
clearAllTaskBtn.addEventListener("click", () => {
113139

114140
// ask for confirmation
115141
if(confirm("All the tasks will be cleared permanently."))
116142
{
117143
taskContainer.setHTML('');
144+
145+
// update task counts
146+
taskCount = 0;
147+
updateTaskCount();
118148
}
119149
});

0 commit comments

Comments
 (0)