Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/JavaScript">
- function get(eid) {return document.getElementById(eid);};
- function calculate() {
- var P = parseFloat(get('P').value);
- var r = parseFloat(get('r').value);
- var n = parseFloat(get('n').value);
- var t = parseFloat(get('t').value);
- if (isNaN(P) || isNaN(r) || isNaN(n) || isNaN(t)) {
- alert('all inputs must be numbers');
- return;
- }
- var A = P*Math.pow((1 + r/n), n*t);
- get('A').innerHTML = A;
- };
- </script>
- </head>
- <body>
- <pre>
- Calculate the accumulated value of principal on deposit as:
- A = P(1 + r/n)^nt
- where:
- A = amount of money accumulated after n years, including interest
- P = principal amount (the initial amount you borrow or deposit)
- r = annual rate of interest (as a decimal)
- n = number of times the interest is compounded per year
- t = number of years the amount is deposited
- </pre>
- <form>
- <p>
- <input id="P" type="text" /> = P
- (principal)<br />
- <input id="r" type="text" /> = r
- (rate of interest - decimal)<br />
- <input id="n" type="text" /> = n
- (number of times interest is compounded per year)<br />
- <input id="t" type="text" /> = t
- (number of years principal is deposited)<br />
- <input type="button" value="calculate" onclick="calculate()" /><br /><br />
- Accumulated Amount - A = <span id="A"></span>
- <p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement