Design comparison
Solution retrospective
I'm proud that I came up with some solid data fetch syntax. I'm worried that I used the fetch syntax three times, one for each timeframe. I couldn't think of a way to reduce that to one fetch overall, which maybe can be done on "DOMLoaded" event. I also wasn't thrilled with how many lines of JS was required for each data point and I'm looking for ways to reduce all of those lines to keep it cleaner code.
Community feedback
- @HekimianzPosted 4 months ago
Overall great job! Works as intended only issues i see are that you are repeating yourself many times throughout your code... The way i made it so that there was only one fetch was to create an object for each filter inside of the fetch like so:
const dailyData = {}; const weeklyData = {}; const monthlyData = {}; const fetchData = async () => { const response = await fetch("./data.json"); if (!response.ok) { console.error("Could not fetch data!"); } const data = await response.json(); data.forEach((elem) => { dailyData[elem.title] = elem.timeframes.daily; weeklyData[elem.title] = elem.timeframes.weekly; monthlyData[elem.title] = elem.timeframes.monthly; }); }
Im not saying its the correct way, just sharing the way i did it!😁
Marked as helpful0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord