The Code
Code Explanation
This loan calculator requires three inputs from the user: the loan
amount, loan term in months, and annual interest rate. When the user
submits their input, the valueEntered function is
called. This function retrieves and validates the values entered,
ensuring they are positive numbers. The
calcLoan function is then called with these values to
calculate the monthly interest rate, monthly payment, total
principal, total interest, and total loan cost. These values are
then displayed on the page using innerHTML. Lastly, the
displayResults function calculates the monthly interest
rate and payment once more, then generates an amortization schedule
for the loan. This schedule details how each monthly payment is
split between principal and interest, as well as the remaining loan
balance after each payment. The amortization schedule is displayed
in a table on the page. This code is a helpful tool for users to
calculate their monthly loan payments and understand how their
payments are divided between principal and interest over time.