Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Tip calculator app solution

@mahadaamir35

Desktop design screenshot for the Tip calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


I was having some issues with the input validation. If you enter a number and then add any kind of character no error will be displayed. Any kind of feedback to tackle this problem will be appreciated.

Community feedback

P

@mihalymarcell86

Posted

Hello @mahadaamir35,

good job on the challenge!

The problem with the input validation occurs, because the parseFloat function only returns NaN, when the first non-whitespace character cannot be converted to a number, which doesn't exclude the possibility of trailing letters. You can either use RegExp, to check for a pattern, like /^\d+$/.test(enteredValue), or you could set the <input> element to type='number' which will automatically disallow the input of non-numeric characters (except +, - and .).

Hope, this helps!

Marked as helpful

0

@mahadaamir35

Posted

@mihalymarcell86 Hi Marchel,

Yeah I was having this issue while using parseFloat. The input element when set to number should make this problem easier for me.

Thanks for the feedback.

0
Elaine 11,400

@elaineleung

Posted

Hi Mahad, good job tackling this challenge. I tried out your app; it looks like the calculation might needs some fixing as well, as the numbers don't seem to look right (e.g., a $100 meal between 2 people with 5% tips gave me $5 tips per person but the total per person is only $10!). Also, I looked at your code and saw that you're using input type="text". Try using number instead of text, and if you add a CSS rule for invalid input (e.g., input:invalid { border: 1px solid red}), you might be able to test out whether invalidation is being called. I also completed this challenge, and you can check out my solution here: https://www.frontendmentor.io/solutions/responsive-tip-calculator-app-with-plain-js-Nj1Gtzub_V

Good luck!

Marked as helpful

0

@mahadaamir35

Posted

@elaineleung Hi Elaine, yeah I honestly had no absolute idea about how the calculation would work. What I did was that the tip percentage was calculated based on the value of bill entered and then this was the tip amount for a single person. This answer was then multiplied with the total number of people. If I would appreciate it if you could inform me about how the calculation was to be correctly done.

Thank you for the feedback.

0

Please log in to post a comment

Log in with GitHub
Discord logo

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