sorteio-sp's People
sorteio-sp's Issues
sorteio-sp
<h2>Sorteio</h2>
<form id="sorteioForm">
<label for="nomesInput">Digite os nomes (separados por vírgula):</label>
<input type="text" id="nomesInput" name="nomesInput" placeholder="nome1, nome2, ..., nome30" required>
<label>Selecione os lugares:</label>
<div>
<!-- Adicione um checkbox para cada lugar -->
<input type="checkbox" id="SalaoDoAltar" name="local" value="SalaoDoAltar" checked>
<label for="SalaoDoAltar">Salão do Altar</label>
<input type="checkbox" id="SalaoDaFrente" name="local" value="SalaoDaFrente" checked>
<label for="SalaoDaFrente">Salão da Frente</label>
<input type="checkbox" id="SalaoDoFundo" name="local" value="SalaoDoFundo" checked>
<label for="SalaoDoFundo">Salão do Fundo</label>
<input type="checkbox" id="Vestiario" name="local" value="Vestiario" checked>
<label for="Vestiario">Vestiário</label>
<input type="checkbox" id="Estoque" name="local" value="Estoque" checked>
<label for="Estoque">Estoque</label>
<!-- Adicione os outros checkboxes para os lugares -->
</div>
<button type="button" onclick="realizarSorteio()">Realizar Sorteio</button>
</form>
<h3>Resultado do Sorteio</h3>
<pre id="resultado"></pre>
<script>
function realizarSorteio() {
// Obter valores do campo de entrada de nomes
var nomesInput = document.getElementById("nomesInput").value;
var nomes = nomesInput.split(',').map(function(item) {
return item.trim();
});
// Obter valores dos checkboxes de lugar
var lugares = [];
var checkboxesLugares = document.getElementsByName("local");
for (var j = 0; j < checkboxesLugares.length; j++) {
if (checkboxesLugares[j].checked) {
lugares.push(checkboxesLugares[j].value);
}
}
// Verificar se há pelo menos uma pessoa e um lugar selecionado
if (nomes.length > 0 && lugares.length > 0) {
// Embaralhar aleatoriamente os participantes
nomes = shuffleArray(nomes);
// Distribuir igualmente os participantes nos lugares
var distribuicao = {};
for (var k = 0; k < nomes.length; k++) {
var lugarIndex = k % lugares.length;
var nome = nomes[k];
var lugar = lugares[lugarIndex];
if (!distribuicao[lugar]) {
distribuicao[lugar] = [];
}
// Verificar se o lugar é "Estoque" e já tem um nome
if (lugar === 'Estoque' && distribuicao[lugar].length === 1) {
// Ignorar este nome e não adicionar ao resultado
continue;
}
distribuicao[lugar].push(nome);
}
// Exibir o resultado
document.getElementById("resultado").innerText = JSON.stringify(distribuicao, null, 2);
} else {
// Exibir mensagem se nenhum nome ou lugar estiver selecionado
document.getElementById("resultado").innerText = "Por favor, digite os nomes e selecione pelo menos um lugar.";
}
}
// Função para embaralhar um array (Fisher-Yates shuffle)
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
</script>
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.