let totalComparisons; function initializeSorter() { // ... (existing code) totalComparisons = (filteredSongs.length * (filteredSongs.length - 1)) / 2; updateProgress(); } function chooseSong(choice) { history.push({ pair: [filteredSongs[0], filteredSongs[1]], choice: choice, loserIndex: 1 - choice }); rankings[filteredSongs[choice]]++; let loser = filteredSongs.splice(1 - choice, 1)[0]; if (filteredSongs.length > 1) { filteredSongs.splice(Math.floor(Math.random() * (filteredSongs.length - 1) + 1), 0, loser); } else { filteredSongs.push(loser); } updateProgress(); displayNextPair(); } function updateProgress() { const completedComparisons = totalComparisons - (filteredSongs.length * (filteredSongs.length - 1)) / 2; const progress = Math.round((completedComparisons / totalComparisons) * 100); document.getElementById('progress').textContent = `Progress: ${progress}%`; }