Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const scoreForm = document.getElementById('score-form');
+ const notification = document.getElementById('notification');
+ const leaderboardBody = document.getElementById('leaderboard-body');
+ const chatForm = document.getElementById('chat-form');
+ const chatInput = document.getElementById('chat-input');
+ const chatMessages = document.getElementById('chat-messages');
+
+ let scores = [];
+ let chat = [];
+
+ scoreForm.addEventListener('submit', function(event) {
+ event.preventDefault();
+ const course = document.getElementById('course').value;
+ const score = parseInt(document.getElementById('score').value);
+ const handicap = parseInt(document.getElementById('handicap').value);
+
+ const netScore = score - handicap;
+ scores.push({ course, score, handicap, netScore });
+ updateLeaderboard();
+
+ notification.textContent = `Score submitted for ${course}!`;
+ notification.style.display = 'block';
+ setTimeout(() => {
+ notification.style.display = 'none';
+ }, 3000);
+
+ scoreForm.reset();
+ });
+
+ chatForm.addEventListener('submit', function(event) {
+ event.preventDefault();
+ const message = chatInput.value;
+ chat.push(message);
+ updateChat();
+ chatInput.value = '';
+ });
+
+ function updateLeaderboard() {
+ leaderboardBody.innerHTML = '';
+ scores.sort((a, b) => a.netScore - b.netScore).forEach((score, index) => {
+ const row = document.createElement('tr');
+ row.innerHTML = `
+
${index + 1} | +
${score.course} | +
${score.netScore} | + `;
+ leaderboardBody.appendChild(row);
+ });
+ }
+
+ function updateChat() {
+ chatMessages.innerHTML = '';
+ chat.forEach(message => {
+ const div = document.createElement('div');
+ div.textContent = message;
+ chatMessages.appendChild(div);
+ });
+ chatMessages.scrollTop = chatMessages.scrollHeight;
+ }
+ });