-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (62 loc) · 1.88 KB
/
script.js
File metadata and controls
70 lines (62 loc) · 1.88 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const taskList = document.querySelector('.task-list');
function enterKey(event) {
if (event.key == 'Enter') {
addTodo();
}
}
loadTodo();
function loadTodo() {
const taskStorage = localStorage.getItem('taskStorage');
if (taskStorage != null) {
taskList.insertAdjacentHTML('beforeend', taskStorage);
countPendingTasks();
}
}
function addTodo() {
const inputTodo = document.getElementById('inputTodo');
if (inputTodo.value != '') {
const element = `
<div class="task">
<button onclick="checkBtn(this)" class="check-btn" aria-label="Check">
<i class='bx bx-check'></i>
</button>
<span onclick="checkBtn(this)">${inputTodo.value}</span>
<button onclick="deleteBtn(this)" class="delete-btn" aria-label="Delete">
<i class='bx bx-trash' ></i>
</button>
</div>
`;
taskList.insertAdjacentHTML('afterbegin', element);
saveTodo();
countPendingTasks();
inputTodo.value = '';
} else {
alert('Please enter a task!');
}
}
function checkBtn(element) {
const task = element.parentElement;
task.classList.toggle('true');
saveTodo();
countPendingTasks();
}
function deleteBtn(element) {
const task = element.parentElement;
task.remove();
saveTodo();
countPendingTasks();
}
function countPendingTasks() {
const countPendingTasks = document.getElementById('CountPendingTasks');
countPendingTasks.textContent = document.querySelectorAll('.task:not(.true)').length;
}
function clearAll() {
if (confirm('Clear all tasks?')) {
taskList.innerHTML = '';
saveTodo();
countPendingTasks();
}
}
function saveTodo() {
localStorage.setItem('taskStorage', taskList.innerHTML);
}