(sum, percentage, locale, currency, printHTML)
| 39 | |
| 40 | // Create a finalTip object with all the data. Send it to the printHTML callback. |
| 41 | const tipCalculator = (sum, percentage, locale, currency, printHTML) => { |
| 42 | let tip = sum * (percentage / 100); |
| 43 | let total = sum + tip; |
| 44 | |
| 45 | const finalTip = { |
| 46 | sum: formatter(locale, currency, sum), |
| 47 | percentage: percentage + "%", |
| 48 | tip: formatter(locale, currency, tip), |
| 49 | total: formatter(locale, currency, total), |
| 50 | }; |
| 51 | |
| 52 | printHTML(finalTip); |
| 53 | }; |
| 54 | |
| 55 | tipCalculator(29.95, 18, "de-DE", "EUR", printHTML); |