-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchap6assign2.htm
More file actions
54 lines (44 loc) · 1.43 KB
/
chap6assign2.htm
File metadata and controls
54 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<head>
<title>Chapter 6 Assignment 2</title>
<script type="text/javascript">
function monthly_pymt(monthly_int_rate, num_months, loan_amount)
{
var base = Math.pow(1 + monthly_int_rate, num_months);
var payment = (loan_amount * monthly_int_rate / (1-(1/base))).toFixed(2);
return payment;
}
function lb()
{
document.write("<br>");
}
var vehicle_price = Number(prompt("Please enter the vehicle price")).toFixed(2);;
var down_payment = Number(prompt("Please enter the down payment amount")).toFixed(2);;
var annual_int_rate = Number(prompt("Please enter the annual interest rate for the loan"));
</script>
</head>
<body style="background-color: tan">
<script type="text/javascript">
var num_months;
var loan_amount = (vehicle_price - down_payment).toFixed(2);
var monthly_int_rate = annual_int_rate / 1200;
document.write("<h1>Loan Calculator</h1>");
lb();
document.write("Vehicle price: $" +vehicle_price);
lb();
document.write("Down payment: $" +down_payment);
lb();
document.write("Interest Rate: " +annual_int_rate+ "%");
lb();
document.write("Loan Amount: $" +loan_amount);
lb();
document.write("<pre># of Months Payment/month</pre>")
for(var year= 2; year < 6; year ++)
{
num_months = year * 12;
document.write("<pre> "+num_months+" "+ monthly_pymt(monthly_int_rate, num_months, loan_amount)+"</pre>");
}
</script>
</body>
</html>