Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. Investment Form

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.

• Sounds like homework!

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

• 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.

• Could you please include how the computation would work

• 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:-

Code:
<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.

• 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.
Code:
<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>

• 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.

• Originally Posted by Philip M
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

• Originally Posted by Saint_Dragon
i change it to what you said and now it says error function expected
What did I say? Just stick with the code you were given.

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

• Thanks ive figured it out and its working.!

cheers.

•

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•