File size: 1,065 Bytes
4c4ca30 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | document.addEventListener('DOMContentLoaded', () => {
const decideBtn = document.getElementById('decide-btn');
const answerText = document.getElementById('answer-text');
const answerContainer = document.getElementById('answer-container');
decideBtn.addEventListener('click', () => {
// Get random answer
const randomIndex = Math.floor(Math.random() * answers.length);
const answer = answers[randomIndex];
// Reset animation class
answerText.classList.remove('fade-in');
answerText.classList.add('hidden');
// Force reflow to restart animation
void answerText.offsetWidth;
// Display answer with animation
answerText.textContent = answer;
answerText.classList.remove('hidden');
answerText.classList.add('fade-in');
// Shake the button for fun
decideBtn.classList.add('animate-pulse');
setTimeout(() => {
decideBtn.classList.remove('animate-pulse');
}, 500);
});
}); |