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

Responsive tip calculator built using React

react, bootstrap
P
Kuvashnee Naidoo•450
@KuvashneeNaidoo
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?

I am glad that I used React as the useState hook helped to manage the state and rendering of the calculations, allowing for efficient updates to the UI. I will perhaps explore using other React hooks such as useRef to directly access DOM elements.

What challenges did you encounter, and how did you overcome them?

One of the most challenging parts of creating this calculator was ensuring that all elements were styled correctly and responsive to different screen sizes. I made the calculator responsive through a combination of Flexbox for centering, a maximum container width, CSS Grid for button layout and a media query to add a breakpoint in order to adjust a column.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • kunal90803•550
    @kunal90803
    Posted 3 months ago

    Great work, @KuvashneeNaidoo

    I really appreciate the structure and clarity of your code, especially the way you include comments to enhance readability. Your approach makes it easy to understand and maintain.

    I did notice a small detail—you've set the type attribute in the input tag as "text". It would be better to use "number" instead. Additionally, to remove the default up and down arrows in the input box, you can add the following CSS:

    input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
    

    Other than that u done a great job and best of luck of future ahead.

    HAPPY CODING 😊.

    Marked as helpful
  • P
    Miran Legin•740
    @miranlegin
    Posted 3 months ago

    Hi @KuvashneeNaidoo,

    First of all, congratulations on completing this challenge!

    There are still a couple of things that could be improved, so let's get started.

    The use of h[x] tags seems arbitrary, and I personally don't think anything other than <h1> fits this project. For instance, <h1>Splitter App</h1> or something similar would work well here. Other than that, no other h[x] tags are appropriate.

    Speaking of tags, you could use <label> elements linked with <input> instead of using <h6>. That would help with accessibility and also would create a link between labels and inputs.

    Applying border only of :focus makes input elements change it's size and the whole lest side area jumps because 4px is added on focus to the input element.

    .input input:focus {
        border: 2px solid #26c0ab;
        outline: none;
    }
    

    To prevent this from happening you could apply border to default input styling but leave it transparent like so

    .input input {
        border: 2px solid transparent;
        outline: none;
    }
    

    and only change color when in focused state, like

    .input input:focus { border-color: #26c0ab; }

    That would always create border but only change it's color when in focused state, preventing content jumps.

    You could also put some event listeners on "Bill" and "Number of people" as well because as much as you cannot calculate "Tip amount" you can definitely calculate "Total amount" without any Tip percentage selected. Meaning that you don't need to select tip to calculate Total/person amount.

    Last but not least you can use <input type="radio" name="tip" /> for all the Tip buttons instead of regular buttons which is more suitable for this kind of functionality. There is no need to keep track of which button is triggered because input with type="radio" can only have single element active at a time. The rule is they need to share the same "name" attribute for this functionality to work, for example

    <input type="radio" name="tip" id="5" />
    <input type="radio" name="tip" id="10" />
    <input type="radio" name="tip" id="15" />
    <input type="radio" name="tip" id="25" />
    

    etc...

    Hope this helps.

    Happy coding! Miran

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

Oops! 😬

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

Log in with GitHub