The Code
In this challange we were given formulas to break down the costs over the entire life of a loan.
GetValues()
GetValues is our entry point where we get all of the input values and pass them to our function to calculate all of our date.
CalculateTotals()
Once we get our inputs, we initialize an object to save all of our data to be displayed later. We loop from month one till the input value for the loan term, creating an object for each month of the loan and pushing this monthly data into our loanData array. Once we have finished calculating the data we hand it off to our display function that handles adding the data to the page.
DisplayTotalResults()
Finaly after our data for the loan has been calculated we display it to the page. First we grab all of our needed elements in the page, then set the quick results card at the top of the page to the correct values, converting the values to display as US Dollar currency. After the quick results card is done we create a table for the month by month breakdown of the loan. To do this we loop through our loanData array and create a row that displays the data for each month object. To ensure this is displays correctly we use .toFixed(2)
on each of our data points rounding the calculated value to 2 decimal points.