Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 4 months ago

Tip Calculator App using modular javascript and BEM

bem
P
Carlos Samuel•350
@Crtykwod
A solution to the Tip calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?
  • Debouncing implementation that significantly improves calculator performance:
export const debounce = (func, wait) => {
  let timeout;
  return function executedFunction(...args) {
    const later = () => {
      clearTimeout(timeout);
      func(...args);
    };
    clearTimeout(timeout);
    timeout = setTimeout(later, wait);
  };
};

This elegant solution prevents excessive calculations during rapid user input, making the calculator more efficient.

  • Robust number formatting system that handles all edge cases:
export const formatters = {
  currency: (input) => {
    // Formatting Logic
  },
  
  percentage: (input) => {
    // Formatting Logic
  }
};
  • Clean modular code structure with separate concerns (validation, utils, events)
What challenges did you encounter, and how did you overcome them?
  • Start with BEM methodology from the beginning: Instead of refactoring later, implementing BEM from the start would create a more maintainable structure and avoid the need to rename classes and restructure HTML/CSS later in development. This would save time and ensure consistent component organization throughout the project.

  • Implement keyboard navigation accessibility features earlier: Building accessibility from the ground up would create a more inclusive application and prevent the need to retrofit keyboard controls. This includes proper tab ordering, ARIA labels, and keyboard shortcuts for all interactive elements.

  • Create more reusable components from the start: Breaking down the calculator into smaller, reusable components initially would make the code more modular and easier to maintain. The number formatting and validation systems could be designed as standalone modules that could be used in other projects.

These changes would improve the development workflow and result in a more robust final product.

What specific areas of your project would you like help with?
  • Is the current debounce timing (150ms) optimal for user experience?
  • How could the BEM structure be improved further for better component isolation?
  • Could the validation system be more robust while maintaining its simplicity?
Code
Couldn’t fetch repository

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    Anamay•450
    @anamaydev
    Posted 3 months ago

    Hi @Crtykwod, The code structure looks clean and well organised. I noticed a couple of UI consistency opportunities that could elevate the design further:

    1. Alignment Consistency : The Select Tip % heading is centered, while other labels like Bill and Number of People are left-aligned. Aligning all labels to the start (left) would create visual harmony across the form.
    2. Error State Border Issue : In the CSS for .error states, the ::placeholder pseudo-element is unintentionally adding an inner border when an error occurs. Removing .error::placeholder from the selector list would resolve the double-border glitch
    /* Before */
    .error, .error::placeholder, .error:hover, .error:focus { ... }
    
    /* After */
    .error, .error:hover, .error:focus { ... }
    
    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, SASS, 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