Changed around line 1
+ const players = [];
+ const notificationArea = document.getElementById('notification-area');
+ const leaderboardBody = document.getElementById('leaderboard-body');
+
+ document.getElementById('score-form').addEventListener('submit', function(e) {
+ e.preventDefault();
+
+ const name = document.getElementById('name').value;
+ const grossScore = parseInt(document.getElementById('score').value);
+ const handicap = parseInt(document.getElementById('handicap').value);
+ const courseHandicap = parseInt(document.getElementById('course-handicap').value);
+
+ const netScore = grossScore - handicap - courseHandicap;
+
+ const player = {
+ name,
+ grossScore,
+ handicap,
+ courseHandicap,
+ netScore,
+ date: new Date()
+ };
+
+ players.push(player);
+ updateLeaderboard();
+ showNotification(`${name} scored a net ${netScore}!`);
+
+ // Clear form
+ this.reset();
+ });
+
+ function updateLeaderboard() {
+ // Sort players by net score
+ players.sort((a, b) => a.netScore - b.netScore);
+
+ // Clear current leaderboard
+ leaderboardBody.innerHTML = '';
+
+ // Add new rows
+ players.forEach((player, index) => {
+ const row = document.createElement('tr');
+
+ const rankCell = document.createElement('td');
+ rankCell.textContent = index + 1;
+
+ const nameCell = document.createElement('td');
+ nameCell.textContent = player.name;
+
+ const scoreCell = document.createElement('td');
+ scoreCell.textContent = player.netScore;
+
+ row.appendChild(rankCell);
+ row.appendChild(nameCell);
+ row.appendChild(scoreCell);
+
+ leaderboardBody.appendChild(row);
+ });
+
+ // Show update notification
+ if (players.length > 1) {
+ showNotification('Leaderboard updated!');
+ }
+ }
+
+ function showNotification(message) {
+ notificationArea.textContent = message;
+ notificationArea.style.display = 'block';
+
+ setTimeout(() => {
+ notificationArea.style.display = 'none';
+ }, 3000);
+ }