show better teams
remove duplicate names and show number of players in a team
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
|
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
|
||||||
<title>Volleyball Team Randomizer</title>
|
<title>Volleyball Team Randomizer</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
|
<script src="script.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
<h1>Enter player names (each row represents one player)</h1>
|
<h1>Enter player names (each row represents one player)</h1>
|
||||||
|
|
||||||
<textarea rows="18" cols="30" name="playerNames" required="required" id="playerNames"></textarea>
|
<textarea rows="18" cols="30" name="playerNames" required="required" id="playerNames"></textarea>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
@@ -46,6 +48,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script src="script.js"></script>
|
|
||||||
|
|
||||||
</body></html>
|
</body></html>
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ function randomizeTeams() {
|
|||||||
.split('\n')
|
.split('\n')
|
||||||
.map(function(str){return str.trim();})
|
.map(function(str){return str.trim();})
|
||||||
.filter(function(str){return str}); // boolean interpretation is same as non-empty
|
.filter(function(str){return str}); // boolean interpretation is same as non-empty
|
||||||
|
// remove duplicates by using a Set
|
||||||
|
names = [...new Set(names)];
|
||||||
|
|
||||||
teams = Array.from({ length: teamCount }, () => []);
|
teams = Array.from({ length: teamCount }, () => []);
|
||||||
playersPerTeam = Math.floor(names.length / teamCount);
|
playersPerTeam = Math.floor(names.length / teamCount);
|
||||||
@@ -35,7 +36,7 @@ function randomizeTeams() {
|
|||||||
function teamstotext(teams){
|
function teamstotext(teams){
|
||||||
textinput = "";
|
textinput = "";
|
||||||
for(let i =0; i < teams.length; i++){
|
for(let i =0; i < teams.length; i++){
|
||||||
textinput += "Team"+ (i+1)+ ": "+ teamtotext(teams[i]) + " <br>";
|
textinput += `Team${i+1}(${teams[i].length}) :${teamtotext(teams[i])} <br>`;
|
||||||
}
|
}
|
||||||
return textinput;
|
return textinput;
|
||||||
}
|
}
|
||||||
@@ -61,5 +62,7 @@ function textchangelistener(){
|
|||||||
elem.style.display = "none";
|
elem.style.display = "none";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
buttons = document.querySelectorAll("input[type='radio']");
|
buttons = document.querySelectorAll("input[type='radio']");
|
||||||
buttons.forEach((x) => x.addEventListener("change", textchangelistener));
|
buttons.forEach((x) => x.addEventListener("change", textchangelistener));
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user