Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 3 years ago

Dashboard using CSS Grid, Javascript and JSON to update values

KurtReti•40
@KurtReti
A solution to the Time tracking dashboard challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


First attempt using CSS Grid, made the layout of the project much easier.

Had trouble with the javascript to keep the time periods white while they were active, and also had trouble having the text read 'hr' instead of 'hrs' when the time was only 0 or 1.

The javascript was quite hacked together and any recommendations to clean up the code so that there is less repeating lines would be much appreciated! :)

Otherwise I enjoyed the project and learned a lot about Grid and a little about JSON and javascript.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Amélie•330
    @aweliego
    Posted almost 3 years ago

    Hi there,

    Well done completing this project! 💪

    The desktop view looks good to me, while the mobile version seems to have too much height, due to the content being stacked vertically instead of occupying the space horizontally. Nice that you use grid areas, the CSS looks pretty neat!

    Regarding how to keep the selected timeframe active: you can use a CSS class for this, that you can add to the timeframe when it's clicked. You can accomplish this using a loop (forEach or for loop). You will also need some code to first remove all active classes when clicking on a timeframe so that only one timeframe remains active at a time. I would also suggest giving that active class to one of the timeframe by default so the user knows which stats are being displayed upon opening the app.

    Changing hrs to hr: you could use an inline ternary statement to reduce the amount of code here, something like ${value === 1 ? 'hr' : 'hrs'}

    As for the general organisation of the code and the repetition pattern:

    • HTML: a lot of divs there, I would make this more semantic; to reduce the amount of HTML I would also create the card elements dynamically through JavaScript instead of hard coding them (though it makes sense you first harde coded them to style them!)
    • If you prefer to have the elements hard coded in your HTML, I would definitely advise to store them in variables to make your code more readable. You can namely store the timeframes and cards in variables with .querySelectorAll() (but you'll need a container for the cards in your HTML for that) and then work through the functionality using a loop to avoid the repetition.
    • You will also probably need to iterate through the JSON object to get the correct values; mind you, I can't be more specific here because I completed the project in React which made this part much less complicated than if written in vanilla JS.

    I understand this is one of your first projects in JavaScript, so good job on making it work and keep at it! The points I highlighted above are pretty common techniques in everyday JavaScript that I use in almost every vanilla JavaScript project.

    Hope this helped and happy coding! 🔥

    Marked as helpful

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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub