Subscribe to Das Buckleheim        RSS Feed
-----

[JS] Interest Calculator

Icon Leave Comment
A small program I made for an assignment in one of my courses that calculates quarterly interest, given a principal and interest rate. I feel as though this isn't nearly as efficient as it could be. If you have any suggestions, I implore you to throw them out there.

Notes:
-We aren't quite at the point in the course in which we script with <script>
-We haven't covered the implementation of variables through "var" quite yet
-We haven't covered loops (if there's such a thing in Javascript, which I'm assuming there is)

<html>
        <!-- A web page that takes in a beginning balance and interest rate from the user
                and compounds it quarterly over the course of a year -->
                
        <head>
                <title>Program 4 - Bank Account Page</title>
        </head>
        
        <body>
                <h1>Interest and Balance Statement for Savings Account</h1>
                <table cellpadding="2">
                        <tr>
                                <td>Beginning Balance:</td>
                                <td>$<input type="text" size="8" id="balance" value="1000"></td>
                        </tr>
                        <tr>
                                <td>Interest Rate:</td>
                                <td><input type="text" size="8" id="interestRate" value="10">%</td>
                        </tr>
                </table>
                <input type="button" value="Calculate" onclick="
                        principal=parseFloat(document.getElementById('balance').value);
                        interestRate=parseFloat(document.getElementById('interestRate').value);
                        interest=principal*(interestRate/100);
                        principal=principal+(principal*(interestRate/100));
                        iTotal=interest;
                        document.getElementById('i1').innerHTML='$' + interest;
                        document.getElementById('p1').innerHTML='$' + principal;
                        interest=principal*(interestRate/100);
                        principal=principal+(principal*(interestRate/100));
                        iTotal=iTotal + interest;
                        document.getElementById('i2').innerHTML='$' + interest;
                        document.getElementById('p2').innerHTML='$' + principal;
                        interest=principal*(interestRate/100);
                        principal=principal+(principal*(interestRate/100));
                        iTotal=iTotal + interest;
                        document.getElementById('i3').innerHTML='$' + interest;
                        document.getElementById('p3').innerHTML='$' + principal;
                        interest=principal*(interestRate/100);
                        principal=principal+(principal*(interestRate/100));
                        iTotal=iTotal + interest;
                        document.getElementById('i4').innerHTML='$' + interest;
                        document.getElementById('p4').innerHTML='$' + principal;
                        document.getElementById('iTotal').innerHTML='$' + iTotal;">
                <hr>
                <table cellpadding="10"  style="text-align:center">
                        <tr>
                                <td><u>Quarter</ul></td>
                                <td><u>Interest Earned</ul></td>
                                <td><u>New Balance</ul></td>
                        </tr>
                        <tr>
                                <td>1</td>
                                <td id="i1">$???</td>
                                <td id="p1">$???</td>
                        </tr>
                        <tr>
                                <td>2</td>
                                <td id="i2">$???</td>
                                <td id="p2">$???</td>
                        </tr>
                        <tr>
                                <td>3</td>
                                <td id="i3">$???</td>
                                <td id="p3">$???</td>
                        </tr>
                        <tr>
                                <td>4</td>
                                <td id="i4">$???</td>
                                <td id="p4">$???</td>
                        </tr>
                </table>
                <table cellpadding="1" border="1">
                        <tr>
                                <td>Total interest earned:</td>
                                <td id="iTotal">$???</td>
                        </tr>
                </table>
        </body>
</html>

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

September 2014

S M T W T F S
 123456
78910111213
1415161718 19 20
21222324252627
282930    

Tags

    Recent Entries

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)