-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.js
44 lines (41 loc) · 1.24 KB
/
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
let todoList = [
{
item: 'Buy Milk',
dueDate: '4/10/2023',
onTime: '8:40'
},
{
item: 'Go to College',
dueDate: '4/10/2023',
onTime: '8:40'
}
];
displayItems();
function addTodo() {
let inputElement = document.querySelector('#todo-input');
let dateElement = document.querySelector('#todo-date');
let timeElement = document.querySelector('#todo-time');
let todoItem = inputElement.value;
let todoDate = dateElement.value;
let todoTime = timeElement.value;
todoList.push({item: todoItem, dueDate: todoDate,onTime:todoTime});
inputElement.value = '';
dateElement.value = '';
timeElement.value = '';
displayItems();
}
function displayItems() {
let containerElement = document.querySelector('.todo-container');
let newHtml = '';
for (let i = 0; i < todoList.length; i++) {
let {item, dueDate,onTime} = todoList[i];
newHtml += `
<span>${item}</span>
<span>${dueDate}</span>
<span>${onTime}</span>
<button class='btn-delete' onclick="todoList.splice(${i}, 1);
displayItems();">Delete</button>
`;
}
containerElement.innerHTML = newHtml;
}