show better teams

remove duplicate names and show number of players in a team
This commit is contained in:
eneller
2024-11-05 21:02:47 +01:00
parent ecbee0765c
commit 0c835d3f7c
2 changed files with 10 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
<title>Volleyball Team Randomizer</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
@@ -30,7 +31,8 @@
<br>
<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>
<button id="generateTeams" onclick="randomizeTeams()">Generate Teams</button>
@@ -46,6 +48,5 @@
<script src="script.js"></script>
</body></html>

View File

@@ -14,7 +14,8 @@ function randomizeTeams() {
.split('\n')
.map(function(str){return str.trim();})
.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 }, () => []);
playersPerTeam = Math.floor(names.length / teamCount);
@@ -35,7 +36,7 @@ function randomizeTeams() {
function teamstotext(teams){
textinput = "";
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;
}
@@ -61,5 +62,7 @@ function textchangelistener(){
elem.style.display = "none";
}
}
buttons = document.querySelectorAll("input[type='radio']");
buttons.forEach((x) => x.addEventListener("change", textchangelistener));
document.addEventListener('DOMContentLoaded', () => {
buttons = document.querySelectorAll("input[type='radio']");
buttons.forEach((x) => x.addEventListener("change", textchangelistener));
});