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 using CSS | Bootstrap | Javascript

Halibal 250

@halibal

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


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

@crsimpson5

Posted

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 helpful

1

Halibal 250

@halibal

Posted

@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 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