Então. Eu não sei como fazer esse código. Eu estava fazendo de um jeito, porém não deu certo, então eu fui tentar usar o código que o professor mandou e ficou essa bagunça kkkk. Conseguem me ajudar?
let listaAmigos = [];
let listaAmigosSorteados = [];
let contador = 0;
function adicionar() {
let campoNomeAmigo = document.getElementById ("nome-amigo");
let nomeAmigo = document.getElementById ("nome-amigo").value;
listaAmigos.push (` ${nomeAmigo}`);
let listaIncluidos = document.getElementById ("lista-amigos");
listaIncluidos.textContent = listaAmigos;
campoNomeAmigo.value = "";
contador++;
}
function sortear() {
embaralhar (listaAmigos);
alert (embaralhar (listaAmigos));
// let numeroSorteado1 = obterNumeroAleatorio (0, listaAmigos.length - 1);
// let numeroSorteado2 = obterNumeroAleatorio (0, listaAmigos.length - 1);
// let amigoSorteado = listaAmigos [numeroSorteado1];
// let amigoSorteadoPresente = listaAmigos [numeroSorteado2];
// if (listaAmigosSorteados.includes (amigoSorteado)) {
// if (contador == 0) {
// return;
// }
// else {
// sortear();
// }
// }
// else {
// listaAmigosSorteados.push (`${amigoSorteado}`);
// let campoSorteados = document.getElementById ("lista-sorteio");
// campoSorteados.textContent = `${amigoSorteado} -> ${amigoSorteadoPresente}`;
// i--;
// }
}
// function obterNumeroAleatorio (min, max) {
// return Math.floor(Math.random() * (max - min + 1)) + min;
// }
function embaralhar(lista) {
for (let indice = lista.length; indice; indice--) {
const indiceAleatorio = Math.floor(Math.random() * indice);
[lista[indice - 1], lista[indiceAleatorio]] = [lista[indiceAleatorio], lista[indice - 1]];
}
}