Responsive results card made with Flexbox, Tailwind & JS
Design comparison
Solution retrospective
My second challenge ! It was more difficult than expected, especially the 4 results components. I realized that I don't know Flexbox that well, it took me a long time to put everything in place. My mistake was to start by desktop design instead of mobile one, as tailwind is more mobile first.
I've put some JS for the first time, just to update results with the data.json. I've tried to do a loop for that but without succeed. I don't know what else I could have done in JS?
Thanks for futur feedbacks !
Community feedback
- @RabberpoliPosted over 1 year ago
Hi! Congrats on completing this challenge! You did a really good job! Back to your question, it is possible to render your results dinamically using JS. I try to explain one of the multiple solutions you can develop:
const scores = [ ]; // here you can put your score objects scores.foreach(score => { const categoryId = score.category + ‘-score’; // Here I’m creating the Id of the HTML element I have to modify const categoryHtmlElement = document.getElementById(categoryId); categoryHtmlElement.innerText = score.score; });
This should give the desired output.
Let me know if it can be useful! Keep going and happy coding!
Marked as helpful0@DavidDHDHPosted over 1 year agoThanks @Rabberpoli ! forEach is the thing ! I managed to redo it my way and incorporated a average score calculation.
const result = document.getElementById('moyenne') const notes = scores.map(score => score.score) // Individuals score display scores.forEach(score => { const idElem = score.category document.getElementById(idElem).innerHTML = score.score }) // average score calculation and display const moyenne = (notes) => { let sum = 0; let count = 0; for (var note of notes) { sum = sum + note; count++; } return sum / count; }; const res = Math.round(moyenne(notes)) result.textContent = res
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