Lanternkami

03-13-2009, 02:31 AM

Hey Everyone ^^

Im working on my final project for DOM and I am having some issues with JavaScript. I have never been a huge fan of it (im much better with PHP) and I have to make a financial loan site. The site is required to have several calculators that calculate loans. I was given an example site with several formulas and working calculators on it, I have to take those formulas and make them my own, which I did with a couple of the easier ones, the ones im having trouble with are the ones that require the use of algebra, I know how to do them on paper i could do them all day on paper lol, but i dont know how to make JavaScript do them. The ones im having issues with are linked below, unfortunately I cant give you the actual link but thats because its on my schools server, but I took some screenshots and posted them.

Here are links to the formulas Im using, the things I cant figure out is how to do these equations in algebra I dont know how to solve for an unkown variable or solve for zero, I know how to do it on paper but not on here.

http://cn.iddqd.net/photos/sample2.jpg

Same with this one:

http://cn.iddqd.net/photos/sample.jpg

and the APR calculator (the second half of it):

http://cn.iddqd.net/photos/sample3.jpg

what i have done so far can be seen here:

http://www.cn.iddqd.net

I did some work on the interest calculator but no matter what i do it still calculates it incorrectly lol. I would really appreciate it if some1 could help me out or at least point me in the right direction, all my teacher told me was "look at the included math functions" which I did, but that didnt really help me all that much. Thanks in advance ^^ :confused:

EDIT* here is the code i have so far:

// This file includes all of my functions on the site

2

3//Tax Functions

//this is the one that woks!

4 function monthlypaymentcalc() {

5 var loan = $('loanamount').value;

6 var rate = $('intrestrate').value;

7 var months = $('monthnum').value;

8 rate = rate / 1200;

9 var loanrate = loan * rate;

10 rate = rate + 1;

11 rate = Math.pow(rate,months);

12 var bottomrate = rate - 1;

13 var toprate = rate * loanrate;

14 var monthlypayment = toprate / bottomrate;

15 monthlypayment = Math.round(monthlypayment);

16 alert ("You will be required to pay $" + monthlypayment + " a Month on this loan.");

17}

//This is the one that doesnt work... right

18function intrestratecalc() {

19 var loan = $('loanamount2').value;

20 var monpay = $('monthlypay').value;

21 var months = $('monthnum2').value;

22 var topnum = months * monpay - loan;

23 var topnum = topnum * 2;

24 var bottomnum = months * loan;

25 var intrestrate = topnum / bottomnum;

26 alert ("Your Intrest Rate will be " + intrestrate +"%.");

27}

//I got confused on this one

28function numberofmonths() {

29 var loan = $('loanamount3').value;

30 var monpay = $('monthlypay2').value;

31 var months = $('intrestrate2').value;

32 alert ("Your Intrest Rate will be " + intrestrate +"%.");

33}

34document.observe("dom:loaded", function()

35{

//just my observes

36 $('monthlypayments').observe("submit", monthlypaymentcalc.bind());

37 $('intrestcalc').observe("submit",intrestratecalc.bind());

38 $('numofmonths').observe("submit",numberofmonths.bind());

39});

I thought i should point out that I am using Prototype

Im working on my final project for DOM and I am having some issues with JavaScript. I have never been a huge fan of it (im much better with PHP) and I have to make a financial loan site. The site is required to have several calculators that calculate loans. I was given an example site with several formulas and working calculators on it, I have to take those formulas and make them my own, which I did with a couple of the easier ones, the ones im having trouble with are the ones that require the use of algebra, I know how to do them on paper i could do them all day on paper lol, but i dont know how to make JavaScript do them. The ones im having issues with are linked below, unfortunately I cant give you the actual link but thats because its on my schools server, but I took some screenshots and posted them.

Here are links to the formulas Im using, the things I cant figure out is how to do these equations in algebra I dont know how to solve for an unkown variable or solve for zero, I know how to do it on paper but not on here.

http://cn.iddqd.net/photos/sample2.jpg

Same with this one:

http://cn.iddqd.net/photos/sample.jpg

and the APR calculator (the second half of it):

http://cn.iddqd.net/photos/sample3.jpg

what i have done so far can be seen here:

http://www.cn.iddqd.net

I did some work on the interest calculator but no matter what i do it still calculates it incorrectly lol. I would really appreciate it if some1 could help me out or at least point me in the right direction, all my teacher told me was "look at the included math functions" which I did, but that didnt really help me all that much. Thanks in advance ^^ :confused:

EDIT* here is the code i have so far:

// This file includes all of my functions on the site

2

3//Tax Functions

//this is the one that woks!

4 function monthlypaymentcalc() {

5 var loan = $('loanamount').value;

6 var rate = $('intrestrate').value;

7 var months = $('monthnum').value;

8 rate = rate / 1200;

9 var loanrate = loan * rate;

10 rate = rate + 1;

11 rate = Math.pow(rate,months);

12 var bottomrate = rate - 1;

13 var toprate = rate * loanrate;

14 var monthlypayment = toprate / bottomrate;

15 monthlypayment = Math.round(monthlypayment);

16 alert ("You will be required to pay $" + monthlypayment + " a Month on this loan.");

17}

//This is the one that doesnt work... right

18function intrestratecalc() {

19 var loan = $('loanamount2').value;

20 var monpay = $('monthlypay').value;

21 var months = $('monthnum2').value;

22 var topnum = months * monpay - loan;

23 var topnum = topnum * 2;

24 var bottomnum = months * loan;

25 var intrestrate = topnum / bottomnum;

26 alert ("Your Intrest Rate will be " + intrestrate +"%.");

27}

//I got confused on this one

28function numberofmonths() {

29 var loan = $('loanamount3').value;

30 var monpay = $('monthlypay2').value;

31 var months = $('intrestrate2').value;

32 alert ("Your Intrest Rate will be " + intrestrate +"%.");

33}

34document.observe("dom:loaded", function()

35{

//just my observes

36 $('monthlypayments').observe("submit", monthlypaymentcalc.bind());

37 $('intrestcalc').observe("submit",intrestratecalc.bind());

38 $('numofmonths').observe("submit",numberofmonths.bind());

39});

I thought i should point out that I am using Prototype