Tip calculator app | Vanilla JS by Alexander MP
Design comparison
Solution retrospective
Is there a more efficient way of writing my JavaScript and to validate the input fields before running the calculator function?
Community feedback
- @DonUggioniPosted about 2 years ago
Hey there,
A few things I've noticed:
The reset button does not reset the total values, seems to be working with all the other parameters though.
For the custom tip, you need to convert the value to a number, right now I believe it is returning a string, so it's not doing the math correctly but it's concatenating the string + number.
You can add an eventListener to all the inputs and pass those into a function that will do the math, after that, then you can create a condition that it only displays the total values after all inputs are filled in.
Something like this:
if(!bill || !tip || !numPerson) return;
That is saying that if any of those values are false, it won't do anything untill all of them are true.
I hope it helps!
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