From 5244c18e535ffb27db6697043f58d08ffa4a35a1 Mon Sep 17 00:00:00 2001 From: Ehab Elasam <75838285+EhabElasam@users.noreply.github.com> Date: Wed, 24 Apr 2024 22:24:03 +0200 Subject: [PATCH] Update tournament.js --- srcs/frontend/js/tournament.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/srcs/frontend/js/tournament.js b/srcs/frontend/js/tournament.js index 6f0755f..dc4af49 100644 --- a/srcs/frontend/js/tournament.js +++ b/srcs/frontend/js/tournament.js @@ -39,12 +39,16 @@ function askPlayerCount() { }); } - function startTournament(playerCount) { console.log(`Tournament with ${playerCount} players is starting.`); const players = []; for (let i = 1; i <= playerCount; i++) { let playerName = prompt(`Enter name for Player ${i}:`); + if (playerName === null) { + window.location.reload(); + return; + } + if (playerName) playerName = playerName.replace(/[^a-z0-9]/gi, '').substring(0, 7); players.push(playerName || `X ${i}`); @@ -53,8 +57,6 @@ function startTournament(playerCount) { showTournament(players, playerCount); } - - function showTournament(players, playerCount) { const canvas = document.getElementById('canvastour'); if (!canvas) return;