-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-toDo.js
49 lines (42 loc) · 1.22 KB
/
11-toDo.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
const toDoList = [];
renderTask();
function addTask() {
const inputTask = document.querySelector('.input-task');
const name = inputTask.value;
const inputdueDate = document.querySelector('.js-dueDate-input');
const dueDate = inputdueDate.value;
if (name !== '' && dueDate !== '') {
toDoList.push({
name,
dueDate,
});
inputTask.value = '';
inputdueDate.value = '';
renderTask();
} else{
alert('PLs enter a task')
}
}
function renderTask() {
let todoListhtml = '';
if (toDoList.length === 0) {
todoListhtml = `<div>Add a todo task</div>`;
} else {
for (let i = 0; i < toDoList.length; i++) {
const todoObject = toDoList[i];
const { name, dueDate } = todoObject;
let html = `
<div>${name}</div>
<div>${dueDate}</div>
<button class="delete-task-btn" onclick="deleteTask(${i})">Delete</button>
`;
todoListhtml += html;
}
}
document.querySelector('.js-task').innerHTML = todoListhtml;
}
function deleteTask(index) {
toDoList.splice(index, 1);
renderTask();
}
console.log(toDoList);