Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const coin = document.getElementById('coin');
+ const flipButton = document.getElementById('flipButton');
+ const result = document.getElementById('result');
+ const themeToggle = document.getElementById('themeToggle');
+
+ let isAnimating = false;
+
+ const flipCoin = () => {
+ if (isAnimating) return;
+
+ isAnimating = true;
+ result.classList.remove('show');
+
+ const random = Math.random();
+ const rotations = 5 * 360; // 5 full rotations
+ const extraRotation = random > 0.5 ? 180 : 0;
+
+ coin.style.transform = `rotateY(${rotations + extraRotation}deg)`;
+
+ setTimeout(() => {
+ result.textContent = random > 0.5 ? 'COROA' : 'CARA';
+ result.classList.add('show');
+ isAnimating = false;
+ }, 1000);
+ };
+
+ const toggleTheme = () => {
+ const currentTheme = document.documentElement.getAttribute('data-theme');
+ const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
+ document.documentElement.setAttribute('data-theme', newTheme);
+ localStorage.setItem('theme', newTheme);
+ };
+
+ // Initialize theme
+ const savedTheme = localStorage.getItem('theme') || 'light';
+ document.documentElement.setAttribute('data-theme', savedTheme);
+
+ // Event listeners
+ flipButton.addEventListener('click', flipCoin);
+ themeToggle.addEventListener('click', toggleTheme);
+
+ // Enable keyboard control
+ document.addEventListener('keypress', (e) => {
+ if (e.code === 'Space') flipCoin();
+ });
+ });