-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (32 loc) · 962 Bytes
/
app.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
const addButton = document.querySelector('.add-todo');
const inputValue = document.querySelector('.input-field');
const todoContainer = document.querySelector('.to-do-list');
addButton.addEventListener('click', () => {
if(inputValue.value.trim() !== '') {
let localData = JSON.parse(localStorage.getItem('todos'));
if(localData === null) {
storeData = []
}else {
storeData = localData
}
storeData.push(inputValue.value)
localStorage.setItem('todos', JSON.stringify(storeData))
inputValue.value = ''
}
displayContent();
})
function displayContent() {
let output = '';
let localData = JSON.parse(localStorage.getItem('todos'));
if(localData !== null) {
localData.forEach((data) => {
output += `
<h3 class="todo-items" >${data} </h3>
`
todoContainer.innerHTML = output;
});
}else {
console.log('No data found');
}
}
displayContent()