
Design comparison
Community feedback
- @TheTrueScoutPosted 4 months ago
Other than the responsiveness being a bit off, it looks great! I do have a question though, I'm new to js, and according to my trusty assistant(gpt) when using fetch, we need to put async before the function- Did you not do it because this project is nothing much(as in, the js isn't heavy, so it'd be fast in fetching the data) or?
Marked as helpful0@SimonbikerPosted 4 months ago@TheTrueScout I could have used the async await and it would be better practice to do so, easier to read and to keep the code more usable in future. As you say its a very simple data that I am getting, I am not needing to create, update or delete.
I need to update the code to something like this. ''' async function getData() { try { const response = await fetch('/data.json'); // Wait for the fetch response const data = await response.json(); // Wait for the JSON parsing json = data;
displayData(currentTimeframe); // Display the data after fetching and parsing
} catch (error) { console.error("Error fetching data:", error); // Handle any errors that occur } } ''' As you can see there are less .then and its easier to read.
1
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