Changed around line 1
+ document.addEventListener('DOMContentLoaded', function () {
+ const betForm = document.getElementById('bet-form');
+ const totalBets = document.getElementById('total-bets');
+ const averageGuess = document.getElementById('average-guess');
+ const betChart = document.getElementById('bet-chart').getContext('2d');
+
+ let bets = [];
+ let chart;
+
+ betForm.addEventListener('submit', function (event) {
+ event.preventDefault();
+ const betValue = parseInt(document.getElementById('bet').value, 10);
+ bets.push(betValue);
+ updateStats();
+ updateChart();
+ betForm.reset();
+ });
+
+ function updateStats() {
+ totalBets.textContent = bets.length;
+ const sum = bets.reduce((a, b) => a + b, 0);
+ const avg = (sum / bets.length).toFixed(2);
+ averageGuess.textContent = avg;
+ }
+
+ function updateChart() {
+ if (chart) {
+ chart.destroy();
+ }
+ chart = new Chart(betChart, {
+ type: 'bar',
+ data: {
+ labels: bets.map((_, i) => `Bet ${i + 1}`),
+ datasets: [{
+ label: 'Bet Values',
+ data: bets,
+ backgroundColor: 'rgba(98, 0, 234, 0.6)',
+ borderColor: 'rgba(98, 0, 234, 1)',
+ borderWidth: 1
+ }]
+ },
+ options: {
+ scales: {
+ y: {
+ beginAtZero: true
+ }
+ }
+ }
+ });
+ }
+ });