Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const scoreForm = document.getElementById('score-form');
+ const chatForm = document.getElementById('chat-form');
+ const notification = document.getElementById('notification');
+ const rankings = document.getElementById('rankings');
+ const chatMessages = document.getElementById('chat-messages');
+
+ // Mock data
+ let scores = [];
+ let messages = [];
+
+ function showNotification(message) {
+ notification.textContent = message;
+ notification.classList.add('show');
+ setTimeout(() => {
+ notification.classList.remove('show');
+ }, 3000);
+ }
+
+ function calculateNetScore(grossScore, handicap, courseRating) {
+ return grossScore - handicap - (courseRating - 72);
+ }
+
+ function updateLeaderboard() {
+ const sortedScores = scores.sort((a, b) =>
+ calculateNetScore(a.score, a.handicap, a.courseRating) -
+ calculateNetScore(b.score, b.handicap, b.courseRating)
+ );
+
+ rankings.innerHTML = sortedScores.map((score, index) => `
+
+ ${index + 1}
+ ${score.player}
+ Net: ${calculateNetScore(score.score, score.handicap, score.courseRating)}
+
+ `).join('');
+ }
+
+ scoreForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const score = {
+ player: 'Current User',
+ course: document.getElementById('course').value,
+ score: parseInt(document.getElementById('score').value),
+ handicap: 12, // Mock handicap
+ courseRating: 72 // Mock course rating
+ };
+
+ scores.push(score);
+ updateLeaderboard();
+ showNotification('Score submitted successfully! 🏌️♂️');
+ scoreForm.reset();
+ });
+
+ chatForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const messageInput = document.getElementById('message');
+ const message = {
+ user: 'Current User',
+ text: messageInput.value,
+ timestamp: new Date()
+ };
+
+ messages.push(message);
+ chatMessages.innerHTML += `
+
+ ${message.user}: ${message.text}
+
+ `;
+
+ chatMessages.scrollTop = chatMessages.scrollHeight;
+ messageInput.value = '';
+ });
+
+ // Initialize with mock data
+ scores.push(
+ {player: 'John', score: 82, handicap: 14, courseRating: 71},
+ {player: 'Sarah', score: 78, handicap: 8, courseRating: 72},
+ {player: 'Mike', score: 85, handicap: 16, courseRating: 73}
+ );
+ updateLeaderboard();
+ });