Back to work

Tip Calculator

A tip calculator that splits the total according to the percentage and the number of people.

Date
May 2022
Category
Frontend
Status
Live

Stack

  • HTML5
  • SCSS
  • JavaScript

Problem

The calculator had to split the tip according to the percentage and the number of people, adapt to mobile and desktop, and disable reset when there was no data to clear.

Role

I implemented the solution with HTML5, SCSS, and vanilla JavaScript, including the calculation logic, the control states, and the responsive layout.

Decisions

  1. Calculation driven by event listeners.

    The bill, percentage, and people fields trigger the calculation, which updates the tip and the total per person in the interface.

  2. Reset enabled only with data.

    The reset button is enabled and disabled by combining JavaScript and styles, so it cannot be used when there is no tip to calculate.

  3. HTML structure before styles.

    I first defined the structure and hierarchy of the blocks with a layout tool, and then applied SCSS and the responsive behavior on top of that foundation.

Result

The calculator produces the tip and the total per person, splits the amount among the diners, keeps reset disabled without data, and adapts to mobile and desktop.