-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (39 loc) · 1.34 KB
/
main.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
let myTodoList = JSON.parse(localStorage.getItem('todo-list')) || [];
showTodoList();
function showTodoList() {
let todoListHtml = '';
for (let i = 0; i < myTodoList.length; i++) {
const todo = myTodoList[i];
const { todoName, date, time } = todo;
const html = `
<div class="todo-info">
<p>${todoName}</p>
</div>
<div class="todo-info">
<p>${date}</p>
</div>
<div class="todo-info">
<p>${time}</p>
</div>
<button onclick="
myTodoList.splice(${i}, 1);
showTodoList();
" class="delete-btn"><img src="https://i.postimg.cc/NMFRVNBY/delete-24dp-E8-EAED-FILL0-wght400-GRAD0-opsz24.png" alt="delete" class="delete-png"></button>
`;
todoListHtml += html;
};
localStorage.setItem('todo-list', JSON.stringify(myTodoList));
document.querySelector('.js-todo-list')
.innerHTML = todoListHtml;
};
function addArray() {
const getArray = document.querySelector('.get-array-js');
const todoName = getArray.value;
const getDate = document.querySelector('.js-get-date');
const date = getDate.value;
const getTime = document.querySelector('.js-get-time')
const time = getTime.value;
myTodoList.push({todoName, date, time});
document.querySelector('.get-array-js').value = '';
showTodoList();
};