From 0c835d3f7c36b1d384cea8bb9d5b9156add7ce21 Mon Sep 17 00:00:00 2001 From: eneller Date: Tue, 5 Nov 2024 21:02:47 +0100 Subject: [PATCH] show better teams remove duplicate names and show number of players in a team --- index.html | 5 +++-- script.js | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index f44d2c6..fa93dda 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ Volleyball Team Randomizer + @@ -30,7 +31,8 @@

Enter player names (each row represents one player)

- + +
@@ -46,6 +48,5 @@ - diff --git a/script.js b/script.js index 18c8a0f..95272fd 100644 --- a/script.js +++ b/script.js @@ -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]) + "
"; + textinput += `Team${i+1}(${teams[i].length}) :${teamtotext(teams[i])}
`; } 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)); \ No newline at end of file +document.addEventListener('DOMContentLoaded', () => { + buttons = document.querySelectorAll("input[type='radio']"); + buttons.forEach((x) => x.addEventListener("change", textchangelistener)); +});