-
Notifications
You must be signed in to change notification settings - Fork 0
/
todolist.js
39 lines (33 loc) · 961 Bytes
/
todolist.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
const arr = JSON.parse(localStorage.getItem('ArrayValue')) || [];
showInWebsite();
function addTodo()
{
const todo=document.querySelector('.inputValue').value;
const date=document.querySelector('.dateValue').value;
arr.push({name: todo,
dueDate:date
});
document.querySelector('.inputValue').value='';
document.querySelector('.dateValue').value='';
showInWebsite();
saveToStorage();
}
function showInWebsite()
{
let toSaveTotalHtml='';
for(let i=0;i<arr.length;i++)
{
const html=`<div>${arr[i].name}</div>
<div>${arr[i].dueDate}</div>
<button onclick="
arr.splice(${i},1);
saveToStorage();
showInWebsite();
" class="deleteButton">Delete</button>`;
toSaveTotalHtml+=html;
}
document.querySelector('.containerForP').innerHTML=toSaveTotalHtml;
}
function saveToStorage(){
localStorage.setItem('ArrayValue',JSON.stringify(arr));
}