Design comparison
Solution retrospective
On JavaScript part, I've dived into some an abyss and repeated many codes. I would appreciate it, if you spare some time to check them out and see if there are any fixes or there is a way to shorten my code.
Community feedback
- @crsimpson5Posted over 2 years ago
Hey, Halibal.
One simple change would be to consolidate your calculatep5, calculatep10, etc. functions into one function, since they all do the same thing. You can define a parameter for the percentage, and then replace the hard-coded number in your function with the variable.
function calculatep(percentage) { ... let tip = billP / percentage /NoPP ... }
And call the function like so:
calculatep(15)
I recently completed this challenge, so you can check out my code if you'd like.
Marked as helpful1@halibalPosted over 2 years ago@crsimpson5 Thanks Curtis, This helped a lot! Changed the code the way as you explained above, it works fine and it is definitely shorter now :)
1
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