Skip to content

Commit 3e6f764

Browse files
committed
Feat: validate newTask message and add it to list
1 parent a733348 commit 3e6f764

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

script.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,28 @@
1-
// ToDo App Logic
1+
const taskInput = document.querySelector("#taskInput");
2+
const taskAddBtn = document.querySelector("#addSvg");
3+
const taskContainer = document.querySelector(".task-container");
4+
const taskField = document.querySelector(".task");
5+
const clearAllTaskBtn = document.querySelector("#clearAllTaskBtn");
6+
7+
// add the task when click
8+
taskAddBtn.addEventListener("click", () => {
9+
// get input field value
10+
const newTask = taskInput.value;
11+
12+
if(newTask !== '' && newTask.length >= 5)
13+
{
14+
// cloning the structure of tasks
15+
const newTaskField = taskField.cloneNode(true);
16+
17+
// select the task text field
18+
const newTaskText = newTaskField.querySelector(".taskText");
19+
newTaskText.textContent = newTask;
20+
21+
taskContainer.append(newTaskField);
22+
23+
taskInput.value = '';
24+
}
25+
else
26+
alert("Task must be of at least 5 characters to be registered.");
27+
28+
});

0 commit comments

Comments
 (0)