HTML and CSS Reference
In-Depth Information
Table 10-16 Mortgage Loan Test Data Set
Data Set
Sales Price
Down Payment
Interest Rate %
Years
Comment
1
23000
4.75
20
The sales price is not
a valid number!
2
123900
24800
A
15
The interest rate is not
a valid number!
3
190000
19000
3.75
30
No error messages
4
231000
45000
5.375
Please select a valid
number from the list
(10, 15, 20, or 30)!
Refresh button
no value selected
from number of years
drop-down list causes
alert box to display
error message
validation logic does not place
result in monthly payment text
field if there is an error; an
error keeps user on the text
field or drop-down menu
user clicks OK
button to re-enter
data as indicated
Figure 10-23
Plan
Calculating the monthly payment.
The monthlyPmt() function requires three parameters: the loan amount (loanAmt), the interest
rate (loanRate), and the number of years that the payments will be made (loanYears). These
values are passed from the CalcLoanAmt() user-defined function to the monthlyPmt() function.
The steps to calculate the monthly payment are as follows:
1. Pass the three variables — loanAmt, loanRate, and loanYears — to the monthlyPmt()
function.
2. Convert the annual interest rate to a monthly interest rate (interestRate) by dividing
loanRate by 1200
3. Convert the number of years to the number of months of payments (Pmts) by
multiplying loanYears by 12
4. Calculate the monthly payment with the following formula:
loanAmt * (interestRate / (1 - (1 / Math.pow(1+interestRate,Pmts))))
5. Return the monthly payment as a fixed decimal value to two decimal places using the
toFixed(2) method.

Search WWH ::

Custom Search