-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
62 lines (43 loc) · 1.4 KB
/
scripts.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
60
61
62
const button = document.querySelector('.button-add-task')
const input = document.querySelector('.input-task')
const listaCompleta = document.querySelector('.list-task')
let minhaListaDeItems = []
function adicionarNovaTarefa() {
minhaListaDeItems.push({
tarefa: input.value,
concluida: false
})
input.value = ""
mostrarTarefas()
}
function mostrarTarefas() {
let novaLi = ''
minhaListaDeItems.forEach((item, index) => {
novaLi = novaLi + `
<li class="task ${item.concluida && "done"}">
<img src="./img/checked.png" alt="check na tarefa" onclick="concluirTarefa(${index})">
${item.tarefa}
<img src="./img/trash.png" alt="lixeira" onclick="deletarItem(${index})">
</li>
`
})
listaCompleta.innerHTML = novaLi
localStorage.setItem('lista', JSON.stringify(minhaListaDeItems))
}
function concluirTarefa(index){
minhaListaDeItems[index].concluida = !minhaListaDeItems[index].concluida
mostrarTarefas()
}
function deletarItem(index){
minhaListaDeItems.splice(index, 1)
mostrarTarefas()
}
function recarregarTarefas(){
const tarefasDoLocalStorage = localStorage.getItem('lista')
if(tarefasDoLocalStorage){
minhaListaDeItems = JSON.parse(tarefasDoLocalStorage)
}
mostrarTarefas()
}
recarregarTarefas()
button.addEventListener('click', adicionarNovaTarefa)