-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (30 loc) · 999 Bytes
/
script.js
File metadata and controls
34 lines (30 loc) · 999 Bytes
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
function guardarNota() {
const nota = document.getElementById('nota').value;
if (nota.trim() === "") return;
let notas = JSON.parse(localStorage.getItem('notas')) || [];
notas.push(nota);
localStorage.setItem('notas', JSON.stringify(notas));
document.getElementById('nota').value = "";
mostrarNotas();
}
function mostrarNotas() {
const lista = document.getElementById('listaNotas');
lista.innerHTML = "";
const notas = JSON.parse(localStorage.getItem('notas')) || [];
notas.forEach((nota, index) => {
const li = document.createElement('li');
li.textContent = nota;
const btn = document.createElement('button');
btn.textContent = "Eliminar";
btn.onclick = () => eliminarNota(index);
li.appendChild(btn);
lista.appendChild(li);
});
}
function eliminarNota(index) {
let notas = JSON.parse(localStorage.getItem('notas')) || [];
notas.splice(index, 1);
localStorage.setItem('notas', JSON.stringify(notas));
mostrarNotas();
}
mostrarNotas();