document.addEventListener('DOMContentLoaded', () => { fetch('/movies') .then(response => response.json()) .then(movies => { const moviesGrid = document.getElementById('movies-grid'); movies.forEach(movie => { const movieElement = document.createElement('div'); movieElement.classList.add('movie'); movieElement.innerHTML = ` ${movie.title}

${movie.title}

`; movieElement.addEventListener('click', () => { window.location.href = `movie.html?title=${encodeURIComponent(movie.title)}`; }); moviesGrid.appendChild(movieElement); }); }); });