From 466756bf14b8eb2a9703db0191f2a51a29d9d181 Mon Sep 17 00:00:00 2001 From: Fariz Adam <165586925+zodiackil37@users.noreply.github.com> Date: Thu, 9 Jan 2025 00:46:36 +0100 Subject: [PATCH] Update main.js Add error handling to the getData function to catch and display errors if the data.json file fails to load. --- main.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.js b/main.js index d1f6390..cd08f14 100644 --- a/main.js +++ b/main.js @@ -231,3 +231,18 @@ function showTheConfetti() { confetti({ ...defaults, particleCount, origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 } }); }, 250); } + +let getData = async () => { + try { + let data = await fetch("./data.json"); + if (!data.ok) throw new Error("Failed to fetch data"); + let objData = await data.json(); + tempData = objData; + fitTheChoses(objData); + hideTheStartInter(objData); + } catch (error) { + console.error("Error fetching data:", error); + alert("An error occurred while loading the quiz data."); + } +}; +