Javascript Loop Program -


i'm trying make javascript loan calculator program. can't seem loop put different numbers on each line. it's suppose show amount of money paid off starting @ 24 months, 36 months, 48 months, , 60 months. i'm using function calculations i'm getting results 24 months. know got change nummonths 36, 48, , 60 have no idea that. thought loop add 12 months each time loops. how format numbers currency? i'm getting long number @ end. tried doing parsefloat on calculate() i'm getting error. here code:

<html> <body bgcolor="#ffc0cb"> <head> <title>chapter 6 assignment 2</title> </head> <body> <h1>loan calculator</h1>  <script type="text/javascript"> var vehicleprice = window.prompt("what vehicle price?", ""); var downpayment = window.prompt("what amount of down payment?", ""); var annualinterest = window.prompt("what annual interest rate loan?", ""); var nummonths = 24 var loanamount = vehicleprice - downpayment var monthlyinterest = annualinterest / 1200  vehicleprice = parsefloat(vehicleprice).tofixed(2); downpayment = parsefloat(downpayment).tofixed(2); loanamount = parsefloat(loanamount).tofixed(2);  function calculate()              {               var baseamount = math.pow(1 + monthlyinterest, nummonths );               return loanamount * monthlyinterest / (1 - (1/baseamount));              }  document.write("vehicle price: $" +vehicleprice+ "<br>"); document.write("down payment: $" +downpayment+ "<br>"); document.write("interest rate: " +annualinterest+ "%<br>"); document.write("loan amount: $" +loanamount+ "<br>");  (var count=2;count<=6;count+=1)     {     document.write(+calculate()+"<br />");     } </script> </body> </html> 

ok, you'll have increment nummonths yourself. this...

for (var count=2;count<=6;count+=1) {     document.write(+calculate()+"<br />");     nummonths += 12; } 

also, can use http://josscrowcroft.github.io/accounting.js/ currency formatting.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -