From 36dbe6ceb54e3add1c96f169efc0e3b5136bfb70 Mon Sep 17 00:00:00 2001 From: Vinayrk69 <141519053+Vinayrk69@users.noreply.github.com> Date: Fri, 8 Aug 2025 23:50:37 +0530 Subject: [PATCH] Update script.js --- movie-app/script.js | 181 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 152 insertions(+), 29 deletions(-) diff --git a/movie-app/script.js b/movie-app/script.js index 469f141..9800a5c 100644 --- a/movie-app/script.js +++ b/movie-app/script.js @@ -6,38 +6,59 @@ const main = document.getElementById('main') const form = document.getElementById('form') const search = document.getElementById('search') -// Get initial movies -getMovies(API_URL) + + async function getMovies(url) { - const res = await fetch(url) - const data = await res.json() + try { + showLoading(); + const res = await fetch(url); + if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`); + const data = await res.json(); - showMovies(data.results) + if (data.results.length === 0) { + main.innerHTML = '
Try searching for a different movie or check your spelling.
${overview ? overview.substring(0, 150) + '...' : 'No overview available.'}
+