-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (45 loc) · 1.62 KB
/
app.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let total = 0
const addButton = document.querySelector(".add-todo");
addButton.addEventListener("click", myfunc);
function myfunc() {
const inputField = document.querySelector(".todo-input");
const todos = document.querySelector(".todo-items");
todos.innerHTML += `<li class="task">
<p>${inputField.value}</p>
<div>
<button class="button-1" onclick="completeTodo(event)">✓</button>
<button class="button-2" onclick="deleteTodo(event)">𝑥</button>
</div>
</li>`
inputField.value = ''
totalTodos()
}
function deleteTodo (event) {
event.preventDefault()
const target = event.target.parentNode.previousElementSibling.textContent
const listOfTodos = document.querySelectorAll('.task')
listOfTodos.forEach(element => {
if (element.children[0].textContent == target) {
element.remove();
}
});
totalTodos()
}
function totalTodos() {
const todos = document.querySelectorAll(".task");
const todoCount = document.querySelector('.todo-count')
todoCount.textContent = todos.length
}
function completeTodo (event) {
const completed = document.querySelector(".total-completed");
const target = event.target.parentNode.previousElementSibling.textContent
const listOfTodos = document.querySelectorAll('.task')
listOfTodos.forEach(element => {
if (element.children[0].textContent == target) {
element.style.color = "lightgrey";
total++
completed.textContent=total
console.log(total)
}
});
}