Skip to content

Commit 1ef9def

Browse files
committed
docs: added comments to JS for understanding
1 parent f028dcf commit 1ef9def

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

script.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ const noTasksMessage = `<div class="completed">
1111
<p>Add a task to plan your day.</p>
1212
</div>`;
1313

14+
// if user clicked on uncheck or check icon, format the task accordingly
1415
const completedTask = (task) => {
1516

1617
const uncheckIcon = task.querySelector("i.pendingSvg");
1718
const editIcon = task.querySelector("i.editSvg");
1819

1920
if(uncheckIcon.className === taskUncompletedIcon)
2021
{
21-
// update icon, disable edit
22+
// update icon, text and disable edit
2223
uncheckIcon.className = taskCompletedIcon;
2324
editIcon.style.display = "none";
2425
task.classList.add("checked");
@@ -34,7 +35,7 @@ const completedTask = (task) => {
3435
}
3536
else
3637
{
37-
// update icon, enable edit
38+
// update icon, text and enable edit
3839
uncheckIcon.className = taskUncompletedIcon;
3940
editIcon.style.display = "block";
4041
task.classList.remove("checked");
@@ -45,6 +46,7 @@ const completedTask = (task) => {
4546
}
4647
}
4748

49+
// edit the task text when clicked on editIcon
4850
const editTaskText = (task) => {
4951

5052
// make the task text editable
@@ -69,6 +71,7 @@ const deleteTask = (task) => {
6971
updateTaskCount();
7072
};
7173

74+
// add new task to the list when clicked on plusIcon or pressed Enter key
7275
const addNewTask = () => {
7376
// get input field value
7477
const newTask = taskInput.value;
@@ -149,7 +152,7 @@ const updateTaskCount = () => {
149152
else
150153
taskCountText.textContent = `You have ${taskCount} pending tasks`;
151154

152-
// check for no tasks in list
155+
// check if noTasksMessage can be added
153156
if(taskCount < 2)
154157
updateNoTaskMessage();
155158
}
@@ -163,6 +166,7 @@ const updateNoTaskMessage = () => {
163166
else if(taskCount === 1)
164167
{
165168
try {
169+
// if newTask is added remove the noTasksMessage
166170
const removeMessage = taskContainer.querySelector(".completed");
167171
removeMessage.remove();
168172
}

0 commit comments

Comments
 (0)