Frontend Mentor - Expenses chart component solution

This is my solution to the Expenses chart component challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the bar chart and hover over the individual bars to see the correct amounts for each day ✅
  • See the current day’s bar highlighted in a different colour to the other bars ✅
  • View the optimal layout for the content depending on their device’s screen size ✅
  • See hover states for all interactive elements on the page ✅
  • Bonus: Use the JSON data file provided to dynamically size the bars on the chart ✅

Screenshot

Links

  • Solution URL: here
  • Live Site URL: here

My process

Built with

  • CSS custom properties
  • Flexbox
  • Mobile-first workflow
  • TypeScript
  • React - JS library

What I learned

This was my first time using typescript in a project. Here's some of the code.

type Props = {
  day: string;
  amount: number;
  index: number;
};

function setColour(): string {
  const dayToday = new Date().getDay();
  return dayToday === index ? "hsl(186, 34%, 60%)" : "hsl(10, 79%, 65%)";
}

const height: string = `${Math.floor((amount / 70) * 100)}%`; // get dynamic heights in percentage

Continued development

Since this was my first time using typescript, I hope to build more projects using it in the future to improve my skills.

Useful resources

  • scrimba - This is in my opinion the best place to learn web development.
  • stack overflow - Whenever I got stuck, I always found some insight here.

Author