Mortgage calculator

Easy
·
45 minutes

Prompt

Create a calculator that accepts three inputs and calculates your monthly mortgage payment:

  1. Principal loan amount
  2. Interest rate (annual)
  3. Number of years on your mortgage

The standard math equation for calculating your monthly mortgage payment is:

P(r(1+r)^n/((1+r)^n)-1))

Where:

  • P is the principal loan amount
  • r is the monthly interest rate
  • n is the total number of payments on your mortgage

Note the bolded differences between the equation variables and the inputs. The inputs are set up that way as a matter of user experience: borrowers tend to be presented numbers like this by their bank. Your job when working on this feature is to convert the user inputs into the numbers that will be used in the calculation. Users will make 12 payments on their mortgage per year of their mortgage, and the monthly interest rate is the annual interest rate divided by 12.

You can use the pictured example to check your math:

  • Principal loan amount: $500,000
  • Interest rate: 3%
  • Length of loan: 30 years
  • => $2,108 monthly mortgage

Submitting solutions

  1. Create a solution by forking one of our CodePen templates:
  2. Submit your solution here

Hints

Additional challenges

Get future questions delivered straight to your inbox for free

Sign up and receive instant access to new questions when we publish them.

We‘ll only use your information to deliver new questions and to provide you updates about our product. We‘ll never spam you or sell your information without your consent. Unsubscribe at any time.