-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
24 lines (21 loc) · 672 Bytes
/
script.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
const form = document.querySelector("form")
const nlwSetup = new NLWSetup(form)
const button = document.querySelector("header button")
button.addEventListener("click", add)
form.addEventListener("change", save)
function add() {
const today = new Date().toLocaleDateString("pt-br").slice(0, -5)
const dayExists = nlwSetup.dayExists(today)
if (dayExists) {
alert("Dia já incluso")
return
}
alert("adicionado com sucesso")
nlwSetup.addDay(today)
}
function save() {
localStorage.setItem("NLWSetup@habits", JSON.stringify(nlwSetup.data))
}
const data = JSON.parse(localStorage.getItem('NLWSetup@habits')) || {}
nlwSetup.setData(data)
nlwSetup.load()