Thursday 15 May 2014

html - Javascript Millionaire Calculator Loop -



html - Javascript Millionaire Calculator Loop -

i'm coding calculator in javascript works out how long take become millionaire calculating next factors: monthly deposit , homecoming on investment. figure out need amortization schedule involvement added onto savings each month. see code:

<!doctype html> <html> <head> <script> function computemillion(){ var deposit = document.getelementbyid('deposit').value; var involvement = document.getelementbyid('return').value; var amount = document.getelementbyid('amount').value; for(var = 0; < 5; i++) { interestpayment = deposit * interest; principalpayment = deposit - interestpayment; principal -= principalpayment; } var months = amount / principal; document.getelementbyid('months').innerhtml = "months millionaire ="+months; } </script> <meta charset="utf-8"> <title>untitled document</title> </head> <body> <p>amount desired: £<input id="amount" type="number" value="1000000" onchange="computemillion()"></p> <p>monthly deposit: £<input id="deposit" type="number" onchange="computemillion()"></p> <p>return on investment: <input id="interest" type="number" onchange="computemillion()">%</p> <h2 id="months"></h2> </body> </html>

so if deposit of £50 made initially, after first month savings should £52.50 because of involvement of 5% user input, next month £50 saved meaning there £102.50 in business relationship , involvement added onto woudl equal £107.62 , on.

can see code isn't working? can come in amounts required no results show @ all.

can help?

thanks

as found...

why bank++ when using i?

for(i = 0; < 5; bank++)

try :

for(var = 0; < 5; i++)

or like..

html :

<p>amount desired: £<input id="amount" type="number" value="1000000" onkeyup="computemillion()"></p> <p>monthly deposit: £<input id="deposit" type="number" onkeyup="computemillion()"></p> <p>return on investment:<input id="interest" type="number" onkeyup="computemillion()">%</p> <h2 id="months"></h2>

js :

function computemillion() { var deposit = document.getelementbyid('deposit').value || 0; var involvement = document.getelementbyid('interest').value || 0; var amount = document.getelementbyid('amount').value || 0; var principal; // var principal = 0; (var = 0; < 5; i++) { interestpayment = deposit * interest; principalpayment = deposit - interestpayment; principal = principalpayment; // principal -= principalpayment; } var months = amount / principal; document.getelementbyid('months').innerhtml = "months millionaire =" + months; }

demo : http://jsfiddle.net/xkr5cky4/

javascript html loops calculator

No comments:

Post a Comment