PDA

View Full Version : Investment Form

Saint_Dragon
05-07-2008, 10:10 AM

i need to create a investment form that allows the user to enter;
- a cash deposit ( e.g. \$5)
- an annual interest rate (e.g. 10%)
- a target savings amount (e.g. \$20)

after the user has entered all of the above required information, after pressing the calculate button the form should be able to calculate how many months it would take to achieve this target amount....

the form needs to be set out in a loop structure.... for example of a loop structure see below;

********************************************************

switch (number) {

else

)
********************************************************

i am stuck on the point where i have created other forms and stuff but im stuck on how to create a mathematical form in this type of structure.

Philip M
05-07-2008, 11:26 AM
Sounds like homework!

Simple or compound interest? Annual, monthly or continuous compounding?

Saint_Dragon
05-07-2008, 12:07 PM
Yeah it is, i dont want somone to do the whole thing for me. Just need some tips to get me started. Anyone?
will rep. It is monthly compound.

rangana
05-07-2008, 12:14 PM
Could you please include how the computation would work :)

Philip M
05-07-2008, 01:23 PM
In the long run it is not in your best interests to get other people to assist you with your homework.

Here is a start:-

<script type = "text/javascript">

var principal = 5;
var months = 0;
var intRate = .12 // i.e. 12 per cent compound per annum = 1&#37; compound per month
var factor = 1 + intRate/12;
var amount = principal;
var target = 20;

while (amount <= target) {
amount = amount * factor;
months ++;
}
amount = amount.toFixed(2);
alert ("At " + intRate*100 + "% compound \$"+ principal + " will compound to \$" + amount + " after " + months + " months" );

</script>

I have no idea how

switch (number) {
else
)

is supposed to fit in.

Saint_Dragon
05-08-2008, 06:00 AM
Heres my code so far.
When i try call the function from a button on my form, it says the script is causing ie explorer to run slow and i have to debug or it will freeze.

<script type="text/javascript">
function calc() {

var deposit = document.iform.dposit.value;
var intRate = document.iform.irate.value/100;
var target = document.iform.taramount.value;
var interest = 1 + intRate/12;
var month = 0;

while

(target >= deposit)
{ deposit = deposit * interest;
month = month +1;
}

target = target.toFixed(2);
document.alert ("At " + intRate/100 + "&#37; compound \$"+ deposit + " will compound to \$" + target + " after " + month + " months" );

}
</script>

Philip M
05-08-2008, 08:05 AM
deposit = deposit(1+ intRate/12);

Now what is wrong with that?

If I were you I would stick with the code you have been given. You need to preserve the initial value of principal (or deposit as you want to call it) which is required for the solution alert.

Saint_Dragon
05-08-2008, 08:25 AM
deposit = deposit(1+ intRate/12);

Now what is wrong with that?

If I were you I would stick with the code you have been given. You need to preserve the initial value of principal (or deposit as you want to call it) which is required for the solution alert.

i change it to what you said and now it says error function expected :confused:

Philip M
05-08-2008, 08:29 AM
i change it to what you said and now it says error function expected :confused:

What did I say? Just stick with the code you were given.

If it ain't broke, work on it until it is.

Saint_Dragon
05-08-2008, 08:58 AM
Thanks ive figured it out and its working.!

cheers.