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;
********************************************************
function dunno(the answer) {
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% 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>
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 + "% compound $"+ deposit + " will compound to $" + target + " after " + month + " months" );
}
</script>
Last edited by Saint_Dragon; 05-08-2008 at 07:09 AM..
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.
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