#####
In this video, we create a javascript function that uses Math.pow() to calculate a mortgage payment.

Hello everyone today we’re going to be given a formula to calculate a mortgage and then take that formula and make a javascript function that does the same thing so let’s um uncomment that so you can read it a little easier so given this formula here which is the payment equals principal times interest divided by 1 minus 1 plus the interest rate to the power

Of the mortgage periods so given that formula we’ll make a javascript function so let’s go ahead and comment that out again and we’ll start out by creating a variable to represent the monthly interest rate since we’re going to be figuring the monthly payment so we need to let the monthly interest equal the interest rate that we’re given divided by 100 because

We need a percent so 3.875 in percentage form would be 0.08 or 03 875 so we divide that by 100 to get the interest rate in the form of a percentage and then we divide that by 12 to get the monthly interest rate okay and then we need to have the number of months that this mortgage will be done will be available or will be in force so the months will equal the

Loan years that we’re given times 12. and that’ll be the number of months okay so now we just need to take the formula and put it into the monthly payment variable so monthly payment equals the interest rate i’m sorry the the loan amount times the monthly interest rate and then divide that by one minus we’re going to use the math dot pow function so we

Can get the to the power of so get the superscript so math pow 1 plus the monthly interest and then to the power of the number of months okay then we’ll return the monthly payment okay let’s go ahead and try that we’ve got the function called down here which is mortgage calculator we put in 250 000 as the amount at a rate of 3.875 percent for 30 years so if

We if we do that it gives us a payment of 1175.5927 and it goes on and on so that’s that’s the answer that’s 1175 a month mortgage payment but uh let’s format that let’s see we can format that to make it look a little better i did find a formatting function here that i’ve used before that i like i’m just going to paste that in so this formatter function is a

Function that’s available and i’ve set it for us dollars and it’s currency it’s a currency of us dollars so in order to apply that we have to formatter.format put in formatter.format and then of course we’ll use the monthly payment so once we put that in we run that then it gives us a nice formatted um amount there so that’s our format or that’s our format for

Our formula it looks like it works well you

Transcribed from video

Javascript Function – Math.pow() – Mortgage Calculator By The Senior Coder