Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const themeBtn = document.getElementById('themeBtn');
+ const searchInput = document.getElementById('searchInput');
+ const searchBtn = document.getElementById('searchBtn');
+ const wordDisplay = document.getElementById('wordDisplay');
+ const definition = document.getElementById('definition');
+ const etymology = document.getElementById('etymology');
+ const resultsSection = document.querySelector('.results-section');
+
+ // Theme toggling
+ const toggleTheme = () => {
+ document.documentElement.setAttribute('data-theme',
+ document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark'
+ );
+ };
+
+ themeBtn.addEventListener('click', toggleTheme);
+
+ // Mock dictionary data
+ const dictionary = {
+ 'example': {
+ definition: 'A representative form or pattern',
+ etymology: 'From Latin exemplum ("sample, pattern")'
+ },
+ 'dictionary': {
+ definition: 'A reference book containing words with their definitions',
+ etymology: 'From Medieval Latin dictionarium ("word book")'
+ }
+ };
+
+ const searchWord = () => {
+ const word = searchInput.value.toLowerCase().trim();
+
+ if (word) {
+ const result = dictionary[word] || {
+ definition: 'Word not found in dictionary',
+ etymology: 'Etymology unavailable'
+ };
+
+ wordDisplay.textContent = word;
+ definition.textContent = result.definition;
+ etymology.textContent = result.etymology;
+
+ resultsSection.classList.add('visible');
+ }
+ };
+
+ searchBtn.addEventListener('click', searchWord);
+ searchInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter') searchWord();
+ });
+
+ // Animation on scroll
+ const observer = new IntersectionObserver((entries) => {
+ entries.forEach(entry => {
+ if (entry.isIntersecting) {
+ entry.target.classList.add('visible');
+ }
+ });
+ });
+
+ observer.observe(resultsSection);
+ });