JS Events w/Conditional?

I’m doing a Tip Calculator:
The problem is:

  • I have the variable called “porcentaje” wich is gonna change depends of the button (10%btn, 15%btn, 20%), And, as you can see the code is repetitive.

How can is put this 3 events onclick (first, second and thridbtn) in the same line and say “if you press first the ‘porcentaje’ its gonna be 10%, second button, 15% and so on…”? It is that posible? i just want to make my code better! i wil love to read your opinion.

Thanks in advance!

CODEPEN: https://codepen.io/ricardonothing/pen/QWywEMj


It looks like the three functions are the same except for the button name, so why not try making the callback a separate named function that takes a single argument of a button name? Then you can reuse that function for all three button events.