Design comparison
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
- @mihalymarcell86Posted over 2 years ago
Hello @mahadaamir35,
good job on the challenge!
The problem with the input validation occurs, because the
parseFloat
function only returnsNaN
, 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 totype='number'
which will automatically disallow the input of non-numeric characters (except +, - and .).Hope, this helps!
Marked as helpful0@mahadaamir35Posted over 2 years ago@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 - @elaineleungPosted over 2 years ago
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 usingnumber
instead oftext
, 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_VGood luck!
Marked as helpful0@mahadaamir35Posted over 2 years ago@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 GitHubJoin 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