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

Mobile First approach Tip Calculator | M/W

Michael Wilson•260
@mikewil245
A solution to the Tip calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


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

Challenges i encountered was trying to figure out how to get the value from the custom tip input , and figured out that i had to add an event listener.

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Ibrahim Morad•380
    @IbrahimMurad
    Posted 5 months ago

    I looked at you code again. It looks a lot better.

    Here are some other suggestions for improvements:

    1. You should remove class="tip-btn" from the custom tip input, this makes this input takes the styles of other buttons. Let it take the common style of input[type="number"], which you did, but the class ruins it when hovered.

    2. Add error messages to other inputs, same as number of customers, and for the style, do not be afraid of breaking everything, I found that all inputs of type number are the same, all labels are the same, and all error messages are the same, you will just add other error messages the same way you did with number of people.

    3. number of people has more than probable bad inputs, zero, negative, and decimal. So, I would recommend leave it empty in the HTML and fill it based on the input, "can't be zero", "can't be negative", or "must be a whole number".

    4. (I am not a js expert but in this project) I found that using Number to convert input value into number is much better, ParseFloat was not predictable for me. Numbers in js can be integers and floats, and the input with type number can not accept alphabets, so Number is more convenient.

    5. Use const instead of let. Any js styling checker will murder you if it sees your js script, they hate it.

    let numOfPeopleValue = parseFloat(numOfPeople.value) || 1; // Default to 1 if invalid
    
      if (!numOfPeopleValue) {
        errorMessage.classList.remove("hidden");
    
        tipTotal.textContent = "$0.00";
        total.textContent = "$0.00";
        return;
      }
    

    Regardless of this project, the condition in if statement will always be false, because parseFloat(numOfPeople.value) has two boolean options, true if it is a value or false if it is NaN, but you did add || 1, so if it is NaN, it will become 1, so !numOfPeopleValue will always be false.

    Marked as helpful
  • Ibrahim Morad•380
    @IbrahimMurad
    Posted 5 months ago
    • You need to add more validations to the inputs, for example, number of people can not be negative or decimal values, bill can not be negative, and custom tip can not be negative and can not exceed 100.

    • Some styles are not applied, such as the chosen tip button should have a different color to indicate it has been chosen.

    Overall, great job. Keep up.

    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

Oops! 😬

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

Log in with GitHub