The Code
The code is structured in 4 functions:
getValues()
Get the values from the HTML inputs and store them in a var.
generateTotalMonthlyPayments()
Calculate the fixed monthly payment.
generateLoanInformation()
Some of the Initial values to be used to build objects
displayLoanInformation()
use that var to create new html table that has rows = number of objects in the array
Entry Point
getValues
The getValues function has two roles:
- Serves as the entery point that triggers all essential functions to accomplish presenting the data to end user.
- Format the inputs and run through a series of checks to ensure valid inputs before table generation.
Calculate Monthly Payments
generateTotalMonthlyPayments
One of the values that needs to be generated to eventually become a cornerstone in calculating the laon table is the monthly payments.
Generate Loan Information
generateLoanInformation
Here I run all the arithmetic to generate all values that will be used on the table section. These values are stored as properties in an object. The object eventually will become a row in the table. A FORLOOP is used to generate and array of objects that will stack in the table to form the length of the loan. This array is returned by the function and passes into the last function as an array of objects.
Display Loan Information
displayLoanInformation
This Function serves to generate the table in a FORLOOP and generate an HTML structure that can be used to make changes to the DOM. Also this function will change the values in the Totals section for the end user to quick referance.