Initial Commit
This commit is contained in:
43
index.html
Normal file
43
index.html
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html><head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
|
||||||
|
<title>Volleyball Team Randomizer</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
<h1>Please select the number of teams:</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<label class="radioButtons" for="twoTeams">
|
||||||
|
<input class="radioButtons" type="radio" name="teams" id="twoTeams" checked="checked">
|
||||||
|
Two teams
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
|
<label class="radioButtons" for="threeTeams">
|
||||||
|
<input class="radioButtons" type="radio" name="teams" id="threeTeams">
|
||||||
|
Three teams
|
||||||
|
</label>
|
||||||
|
<br>
|
||||||
|
<h1>Enter player names (each row represents one player)</h1>
|
||||||
|
<textarea rows="18" cols="30" name="playerNames" required="required" id="playerNames"></textarea>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<button id="generateTeams" onclick="randomizeTeams()">Generate Teams</button>
|
||||||
|
|
||||||
|
|
||||||
|
<p id="teamOutput"></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script src="script.js"></script>
|
||||||
|
|
||||||
|
</body></html>
|
||||||
86
script.js
Normal file
86
script.js
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
|
||||||
|
function randomizeTeams() {
|
||||||
|
let numberSelected = 2;
|
||||||
|
if(document.getElementById("threeTeams").checked == true){
|
||||||
|
numberSelected = 3;
|
||||||
|
}
|
||||||
|
const outputField = document.getElementById("teamOutput");
|
||||||
|
let text = document.getElementById("playerNames").value;
|
||||||
|
text = text.replace(/[^\S\r\n]/g, '');
|
||||||
|
text = text.replace(/^\s*[\r\n]/gm, '');
|
||||||
|
text = text.replace(/^\s*[\r\n]+|[\r\n]+\s*$/g, '');
|
||||||
|
let nameList = text.split('\n');
|
||||||
|
let nameListCopy = [...nameList];
|
||||||
|
|
||||||
|
let playerNumbers = nameList.length;
|
||||||
|
let playerPerTeam = 0;
|
||||||
|
if(numberSelected === 2){
|
||||||
|
playerPerTeam = Math.floor(playerNumbers/numberSelected);
|
||||||
|
|
||||||
|
let team1 = [];
|
||||||
|
let team2 = [];
|
||||||
|
for(let i = 0; i<playerPerTeam;i++){
|
||||||
|
let rndm = Math.floor(Math.random()*nameList.length);
|
||||||
|
let repeat = false;
|
||||||
|
if(!(rndm in nameListCopy)){
|
||||||
|
repeat = true;
|
||||||
|
i = i-1;
|
||||||
|
}
|
||||||
|
if(!repeat){
|
||||||
|
team1.push(nameList[rndm]);
|
||||||
|
delete nameListCopy[rndm];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 0; i<playerNumbers;i++){
|
||||||
|
if(i in nameListCopy){
|
||||||
|
team2.push(nameList[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let outputText = "Team1: " + team1 + "<br>" + "Team2: " + team2
|
||||||
|
|
||||||
|
outputField.innerHTML = outputText;
|
||||||
|
}else if(numberSelected ===3){
|
||||||
|
playerPerTeam = playerNumbers/numberSelected;
|
||||||
|
let team1 = [];
|
||||||
|
let team2 = [];
|
||||||
|
let team3 = [];
|
||||||
|
for(let i = 0; i<playerPerTeam;i++){
|
||||||
|
let rndm = Math.floor(Math.random()*nameList.length);
|
||||||
|
let repeat = false;
|
||||||
|
if(!(rndm in nameListCopy)){
|
||||||
|
repeat = true;
|
||||||
|
i = i-1;
|
||||||
|
}
|
||||||
|
if(!repeat){
|
||||||
|
team1.push(nameList[rndm]);
|
||||||
|
delete nameListCopy[rndm];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
playerPerTeam = Math.floor((playerNumbers-playerPerTeam)/2);
|
||||||
|
for(let i = 0; i<playerPerTeam;i++){
|
||||||
|
let rndm = Math.floor(Math.random()*nameList.length);
|
||||||
|
let repeat = false;
|
||||||
|
if(!(rndm in nameListCopy)){
|
||||||
|
repeat = true;
|
||||||
|
i = i-1;
|
||||||
|
}
|
||||||
|
if(!repeat){
|
||||||
|
team2.push(nameList[rndm]);
|
||||||
|
delete nameListCopy[rndm];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(let i = 0; i<playerNumbers;i++){
|
||||||
|
if(i in nameListCopy){
|
||||||
|
team3.push(nameList[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let outputText = "Team1: " + team1 + "<br>" + "Team2: " + team2 + "<br>" + "Team3: " + team3;
|
||||||
|
|
||||||
|
outputField.innerHTML = outputText;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
47
style.css
Normal file
47
style.css
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
*{
|
||||||
|
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
|
||||||
|
background-color: aquamarine;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea{
|
||||||
|
font-size: 1vh;
|
||||||
|
width: 100%;
|
||||||
|
height:50vh;
|
||||||
|
padding:0;
|
||||||
|
}
|
||||||
|
h1{
|
||||||
|
text-align: center;
|
||||||
|
font-size: 2vh;
|
||||||
|
}
|
||||||
|
.radioButtons{
|
||||||
|
height:2vh;
|
||||||
|
font-size: 2vh;
|
||||||
|
line-height: 2vh;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1em auto;
|
||||||
|
gap: 0.5em;
|
||||||
|
}
|
||||||
|
#teamOutput{
|
||||||
|
|
||||||
|
margin-top:10vh;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 2vh;
|
||||||
|
line-height: 4.5vh;
|
||||||
|
}
|
||||||
|
button{
|
||||||
|
position: absolute;
|
||||||
|
left:50%;
|
||||||
|
margin-top: 5vh;
|
||||||
|
-ms-transform: translate(-50%, -50%);
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
height: 5vh;
|
||||||
|
font-size: 2vh;
|
||||||
|
padding-left: 10%;
|
||||||
|
padding-right: 10%;
|
||||||
|
font-weight:bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user