10.4 Compound Interest Web Page
Let’s put what you’ve learned into practice with a complete web page that uses a while
loop and an external JavaScript file. FIGURE 10.3’s Compound Interest web page generates a table of compound interest values for a user-specified number of years. In the figure, note the initial deposit (often referred to as the “principal”) of $1000 and the interest rate of 10%. Using those values, the table’s year 1 values are calculated as follows. The interest earned is $1000 × 10% = $100, and the ending value is $1000 + $100 = $1100. To verify the table values for years 2 through 4, use the prior ending value as the new starting value and apply the same mathematical calculations.
Get Web Programming with HTML5, CSS, and JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.