To help you create a JavaScript program that calculates mortgage payments and total interest paid, we'll follow the formulas given in the image:
- Monthly payment formula:
[
\text{payment} = p \times r / \left(1 - (1 + r)^{-n}\right)
]
where:
- ( p ) is the amount of the loan
- ( r ) is the monthly interest rate (annual rate divided by 12)
- ( n ) is the duration of the loan in months