-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (33 loc) · 1.35 KB
/
app.js
File metadata and controls
39 lines (33 loc) · 1.35 KB
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
let amigos = [];
function agregarAmigo() {
let amigoInput = document.getElementById('amigo').value.trim();
if (amigoInput !== "") {
amigos.push(amigoInput);
console.log(amigos);
actualizarLista();
document.getElementById('amigo').value = ""; // Limpiar el input después de agregar
} else {
alert("Ingrese un nombre");
}
}
function actualizarLista() {
let ul = document.getElementById('listaAmigos');
ul.innerHTML = ""; // Limpiar la lista antes de actualizar
amigos.forEach(function(amigo) {
let li = document.createElement('li');
li.textContent = amigo;
ul.appendChild(li);
});
}
function botonAgregarAmigo(){
agregarAmigo();
}
function sortearAmigo(){
if (amigos.length === 0) {
alert('Por favor, añade al menos un nombre a la lista.');
return;
}
const amigoSorteado = amigos[Math.floor(Math.random() * amigos.length)];
const resultado = document.getElementById('resultado');
resultado.innerHTML = `El amigo sorteado es: ${amigoSorteado}`;
}