Advertisement
richarduie

compoundInterest.html

Apr 1st, 2013
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.40 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.     <script type="text/JavaScript">
  5.         function get(eid) {return document.getElementById(eid);};
  6.         function calculate() {
  7.             var P = parseFloat(get('P').value);
  8.             var r = parseFloat(get('r').value);
  9.             var n = parseFloat(get('n').value);
  10.             var t = parseFloat(get('t').value);
  11.             if (isNaN(P) || isNaN(r) || isNaN(n) || isNaN(t)) {
  12.                 alert('all inputs must be numbers');
  13.                 return;
  14.             }
  15.             var A = P*Math.pow((1 + r/n), n*t);
  16.             get('A').innerHTML = A;
  17.         };
  18.     </script>
  19. </head>
  20.  
  21. <body>
  22.     <pre>
  23.     Calculate the accumulated value of principal on deposit as:
  24.  
  25.     A = P(1 + r/n)^nt
  26.  
  27.     where:
  28.  
  29.         A = amount of money accumulated after n years, including interest
  30.  
  31.         P = principal amount (the initial amount you borrow or deposit)
  32.         r = annual rate of interest (as a decimal)
  33.         n = number of times the interest is compounded per year
  34.         t = number of years the amount is deposited
  35.     </pre>
  36.     <form>
  37.         <p>
  38.             <input id="P" type="text" /> = P
  39.                 (principal)<br />
  40.             <input id="r" type="text" /> = r
  41.                 (rate of interest - decimal)<br />
  42.             <input id="n" type="text" /> = n
  43.                 (number of times interest is compounded per year)<br />
  44.             <input id="t" type="text" /> = t
  45.                 (number of years principal is deposited)<br />
  46.             <input type="button" value="calculate" onclick="calculate()" /><br /><br />
  47.             Accumulated Amount - A = <span id="A"></span>
  48.         <p>
  49.     </form>
  50. </body>
  51.  
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement