Expenses chart component

Solution retrospective
Completed in 8 hours. At first I tried to do it with chart.js but reading the documentation and implementing it was harder than coding that task from zero. I learned to use 2 parameters in forEach loop and new Date function.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @elaineleung
Hi Paweł, well done on this challenge! I think you did an excellent job with your
forEach
methods, and even if it took a while to figure it all out, I'm sure these are skills that will take you far.I see you using a switch statement for applying the style to the current day bar; most of the code in the cases are actually fairly similar, so you can consider how to make it "DRY-er". Here's what I did instead in my code to condense all that into a ternary operation:
const currentDay = new Date().getDay() data.forEach( (info, idx) => { ... idx !== 6 // this means if the data is not for Sunday, whose idx is 6 ? idx + 1 === currentDay && barDiv.classList.add('highlight') : currentDay === 0 && barDiv.classList.add('highlight') }
One final suggestion I have is to add a
try... catch
for your fetch method in async/await just to catch errors in case there are any.Keep leveling up on that JavaScript! 😊
Marked as helpful - @blayzking
Hi, I keep getting this error, 'Access to fetch has been blocked by CORS Policy.' Did you encounter this? And how did you work your way around it?
Join 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