-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (55 loc) · 1.82 KB
/
script.js
File metadata and controls
68 lines (55 loc) · 1.82 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
const todoList = [];
document.querySelector('.js-add-todo-button')
.addEventListener('click', addTodo);
renderTodoList();
function renderTodoList() {
let todoListHTML = '';
for (let i = 0; i < todoList.length; i++) {
const todoObject = todoList[i];
//const name = todoObject.name;
//const dueDate = todoObject.dueDate;
//const starttime = todoObject.starttime;
const { name, dueDate, starttime} = todoObject;
const html = `
<div class="flex items-center justify-between bg-pink-50 p-2 rounded-lg mb-2">
<div class="flex gap-4 items-center">
<span class="font-medium">${name}</span>
<span class="text-gray-500 text-sm">${dueDate}</span>
<span class="text-gray-500 text-sm">${starttime}</span>
</div>
<button onclick="
todoList.splice(${i}, 1);
renderTodoList();
" class="delete-todo-button bg-red-400 text-white px-2 py-1 rounded hover:bg-red-500 transition">Delete</button>
</div>
`;
todoListHTML += html;
}
document.querySelector('.js-todo-list')
.innerHTML = todoListHTML;
}
function addTodo() {
const inputElement = document.querySelector('.js-name-input');
const name = inputElement.value;
const dateInputElement = document.querySelector('.js-due-date-input');
const time = document.querySelector('.js-starttime');
const starttime=time.value;
const dueDate = dateInputElement.value;
todoList.push({
//name: name,
//dueDate: dueDate,
//starttime: starttime
name,
dueDate,
starttime
});
inputElement.value = '';
renderTodoList();
}
todoList.addEventListener('change', (e) => {
if (e.target.classList.contains('todo-checkbox')) {
const text = e.target.nextElementSibling;
text.classList.toggle('line-through');
text.classList.toggle('text-gray-400');
}
});