The Code
The code is structured in four functions:
getValues()
This function gets the input values that the user has put into the HTML via the webpage. It then assigns those values to variables and converts those values to string using the parseFloat function and one of the values gets converted to an int using the parseInt function. Lastly, it passes those values to the loanCalculation function as parameters.
loanCalculation()
This function receives the values from the getValues function as parameters. It then performs the necessary calculations and uses a for loop to loop through each payment to generate the payment needed for each month and pushes that data to the monthlyPayments variable to be passed to the displayResults function.
displayResults()
This function receives the monthlyPayments variable from the loanCalculation function as a parameter. It then performs the necessary methods to show the results for the top card that displays the principal, total interest, and total cost of the loan. Next, it directs the data to the correct place in the HTML using the getElementById function. Then it loops through all the months of the loan to display the amortization table properly.
formatCurrency()
This small function formats the currency to use the US dollar.