-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (43 loc) · 1.8 KB
/
app.js
File metadata and controls
49 lines (43 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
let list = document.querySelector(".todo ul");
let ToDo = document.querySelector("#addToDo");
let btnAdd = document.querySelector("#addTask");
btnAdd.addEventListener("click", function() {
let newTask = document.createElement("li");
newTask.innerText = ToDo.value;
list.append(newTask);
ToDo.value = "";
let rightSection = document.querySelector(".rightsection");
let textAlert = document.createElement("p");
textAlert.innerText = "You've 1 new pending ToDo for the day!";
textAlert.setAttribute("id","todoAlert");
rightSection.insertAdjacentElement("beforeend", textAlert);
setTimeout( function() {
rightSection.removeChild(textAlert);
}, 4000);
});
let removeToDo = document.querySelector("#deleteToDo");
let btnDelete = document.querySelector("#deleteTask");
btnDelete.addEventListener("click", function() {
let taskText = removeToDo.value.trim();
removeToDo.value = "";
let taskToRemove = list.querySelector("li");
while (taskToRemove) {
if (taskToRemove.innerText === taskText) {
taskToRemove.setAttribute("id","taskRemove");
setTimeout( function() {
list.removeChild(taskToRemove);
}, 2000);
let rightSection = document.querySelector(".rightsection");
let textAlert = document.createElement("p");
textAlert.innerText = `Congrats! You've checklisted ToDo: "${taskText}" for the day!`;
textAlert.setAttribute("id","todoAlert");
rightSection.insertAdjacentElement("beforeend", textAlert);
setTimeout( function() {
rightSection.removeChild(textAlert);
}, 4000);
return;
}
taskToRemove = taskToRemove.nextElementSibling;
}
alert("Task not found!");
});