Problems › JavaScript › billing
Compute the late payment fee
A billing system charges a fixed fee for the first overdue day and a smaller increment for each additional day.
- The first overdue day costs 2500.
- Each further day adds 500.
- Zero or fewer overdue days means no fee.
lateFee(daysLate: int) → int
Where you start
function lateFee(daysLate) {
}
Worked examples
| Call | Result |
|---|---|
lateFee(1) | 2500 |
lateFee(2) | 3000 |
lateFee(5) | 4500 |
lateFee(0) | 0 |
Hint
Subtract one from the count, multiply the increment, and add the base — but only when positive.
Reference solution in JavaScript
function lateFee(daysLate) {
if (daysLate <= 0) return 0;
return 2500 + (daysLate - 1) * 500;
}