no seguinte código da aula 5 de lógica de programação. Não tenho nenhuma resposta ao executar a função 'sortear'.
let amigos = [];
function adicionar() {
let nomeAmigo = document.getElementById('nome-amigo');
listaAmigos = document.getElementById('lista-amigos');
if (nomeAmigo.value == '') {
alert('coloque um nome');
} else {
if (nomeAmigo.value == amigos.includes) {
alert('já esta em uso');
} else {
amigos.push(nomeAmigo.value);
if (listaAmigos.textContent == ''){
listaAmigos.textContent = nomeAmigo.value;
} else {
listaAmigos.textContent = listaAmigos.textContent + ', ' + nomeAmigo.value;
}
//listaAmigos.push(listaAmigos);
nomeAmigo.value = '';
}
}
}
function sortear(amigos) {
embaralha(amigos);
let sorteio = document.getElementById('lista-sorteio');
//código omitido
for (let i = 0; i < amigos.length; i++) {
if (i == amigos.length - 1) {
sorteio.innerHTML = sorteio.innerHTML + amigos[i] + ' --> ' + amigos[0] + '<br>';
} else {
sorteio.innerHTML = sorteio.innerHTML + amigos[i] + ' --> ' + amigos[i + 1] + '<br>';
}
}
//código omitido
}
function embaralha(listaAmigos) {
for (let indice = listaAmigos.length; indice; indice--) {
const indiceAleatorio = Math.floor(Math.random() * indice);
// atribuição via destructuring
[listaAmigos[indice - 1], listaAmigos[indiceAleatorio]] =
[listaAmigos[indiceAleatorio], listaAmigos[indice - 1]];
}
}
function reiniciar() {
amigos = []
document.getElementById('lista-amigos').innerHTML = '';
document.getElementById('nome-amigo').innerHTML = '';
}