| 4 | */ |
| 5 | |
| 6 | const tipCalculator = (sum, percentage, currency, prefix) => { |
| 7 | let tip = sum * (percentage / 100); |
| 8 | let total = sum + tip; |
| 9 | if (prefix) { |
| 10 | console.log(` |
| 11 | Sum before tip: ${currency}${sum} |
| 12 | Tip percentage: ${percentage}% |
| 13 | Tip: ${currency}${tip.toFixed(2)} |
| 14 | Total: ${currency}${total.toFixed(2)} |
| 15 | `); |
| 16 | } else { |
| 17 | console.log(` |
| 18 | Sum before tip: ${sum}${currency} |
| 19 | Tip percentage: ${percentage}% |
| 20 | Tip: ${tip.toFixed(2)}${currency} |
| 21 | Total: ${total.toFixed(2)}${currency} |
| 22 | `); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | tipCalculator(29.95, 18, "kr", false); |