-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterest-rate.html
More file actions
61 lines (54 loc) · 1.83 KB
/
interest-rate.html
File metadata and controls
61 lines (54 loc) · 1.83 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
55
56
57
58
59
60
61
s<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Interest Rate</title>
<style type="text/css" >
table {
width: 300px;
border-collapse:collapse;
background-color:aqua;
}
table,td,th {
border:1px solid black;
padding:4px;
}
th {
text-align: left;
color:aliceblue;
background-color:#4800ff;
}
tr.oddrow {
background-color:aliceblue;
}
</style>
<script>
// declare variables
var principal; //original amount invested (i,e, the principal)
var RATE; // the annual rate
var amount; // the amount on deposit at the end of the each year
// Initialization
principal = 1000.00;
RATE = 0.05;
document.writeln("<table"); //begin the table
document.writeln("<caption>Calculating Compound Interest</caption>");
document.writeln("<thead><tr><th> Year </th>"); // year column heading
document.writeln("<th> Amount on Deposit </th>");
document.writeln("</tr></thead><tbody>");
//processing
for (var year = 1 ; year <= 10; year++) {
amount = principal * Math.pow(1.0 + RATE, year);
if (year % 2 !== 0) {
document.writeln("<tr class='oddrow'><td>" + year + "</td><td>" + amount.toFixed(2) + "</td></tr>");
}
else {
document.writeln("<tr><td>" + year + "</td><td>" + amount.toFixed(2) + "</td></tr>");
}
} //end for loop
//close tbody and table tags
document.writeln("</tbody></table>");
</script>
</head>
<body>
</body>
</html>