document.addEventListener('DOMContentLoaded', function() { const featuredImagesContainer = document.getElementById('featured-images'); const exploreBtn = document.getElementById('exploreBtn'); // Loading spinner function showLoading() { featuredImagesContainer.innerHTML = `
Failed to load images. Please try again later.
'; } } catch (error) { console.error('Error fetching NASA images:', error); featuredImagesContainer.innerHTML = 'Error loading images. Check your connection.
'; } } // Display images in grid function displayImages(images) { featuredImagesContainer.innerHTML = ''; images.forEach((item, index) => { const imageData = item.data[0]; const imageUrl = item.links ? item.links[0].href : 'http://static.photos/space/640x360/' + (index + 1); const card = document.createElement('div'); card.className = 'image-card overflow-hidden'; card.innerHTML = `${new Date(imageData.date_created).getFullYear() || 'Unknown date'}
${imageData.description || 'No description available'}