Design comparison
Solution retrospective
This js is horrible I know, but is there any easier, or better way to do it? If you know let me know!
Happy Coding! :D
Community feedback
- @HK273Posted over 1 year ago
Nice job on the design of this and getting it all working! I feel your pain with the JS on this one aha - I remember doing it myself as one of the first JS based challenges I tried. Firstly, you're going to be much better off actually using the data.json file included, rather than hard coding the values directly in the HTML. Take a look at the fetch API (https://www.w3schools.com/jsref/api_fetch.asp) and map function (https://www.w3schools.com/jsref/jsref_map.asp) for this. What this will allow you to do is render the entire HTML strucutre for each card element and include all of the data (much less code in the long run!). You could then use a similliar method to what you've already implemented to toggle between each data point. You'll also want to take a look at using the forEach method (https://www.w3schools.com/jsref/jsref_foreach.asp) to manage the event listeners assigned to the buttons. Not saying my method is the perfect soltuion for this, but check out my code (https://github.com/HK273/time-tracking-dashboard/blob/main/script/script.js) for this challenge if you want more of a clearer idea on what I'm talking about. Hope this helps!
1@rockdoginafogPosted over 1 year ago@HK273 your solution may not be the best, but it's definetly better than mine haha
thanks for the comment <3
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