@@ -11,14 +11,15 @@ const noTasksMessage = `<div class="completed">
11
11
<p>Add a task to plan your day.</p>
12
12
</div>` ;
13
13
14
+ // if user clicked on uncheck or check icon, format the task accordingly
14
15
const completedTask = ( task ) => {
15
16
16
17
const uncheckIcon = task . querySelector ( "i.pendingSvg" ) ;
17
18
const editIcon = task . querySelector ( "i.editSvg" ) ;
18
19
19
20
if ( uncheckIcon . className === taskUncompletedIcon )
20
21
{
21
- // update icon, disable edit
22
+ // update icon, text and disable edit
22
23
uncheckIcon . className = taskCompletedIcon ;
23
24
editIcon . style . display = "none" ;
24
25
task . classList . add ( "checked" ) ;
@@ -34,7 +35,7 @@ const completedTask = (task) => {
34
35
}
35
36
else
36
37
{
37
- // update icon, enable edit
38
+ // update icon, text and enable edit
38
39
uncheckIcon . className = taskUncompletedIcon ;
39
40
editIcon . style . display = "block" ;
40
41
task . classList . remove ( "checked" ) ;
@@ -45,6 +46,7 @@ const completedTask = (task) => {
45
46
}
46
47
}
47
48
49
+ // edit the task text when clicked on editIcon
48
50
const editTaskText = ( task ) => {
49
51
50
52
// make the task text editable
@@ -69,6 +71,7 @@ const deleteTask = (task) => {
69
71
updateTaskCount ( ) ;
70
72
} ;
71
73
74
+ // add new task to the list when clicked on plusIcon or pressed Enter key
72
75
const addNewTask = ( ) => {
73
76
// get input field value
74
77
const newTask = taskInput . value ;
@@ -149,7 +152,7 @@ const updateTaskCount = () => {
149
152
else
150
153
taskCountText . textContent = `You have ${ taskCount } pending tasks` ;
151
154
152
- // check for no tasks in list
155
+ // check if noTasksMessage can be added
153
156
if ( taskCount < 2 )
154
157
updateNoTaskMessage ( ) ;
155
158
}
@@ -163,6 +166,7 @@ const updateNoTaskMessage = () => {
163
166
else if ( taskCount === 1 )
164
167
{
165
168
try {
169
+ // if newTask is added remove the noTasksMessage
166
170
const removeMessage = taskContainer . querySelector ( ".completed" ) ;
167
171
removeMessage . remove ( ) ;
168
172
}
0 commit comments