Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-07-2008, 09:10 AM   PM User | #1
Saint_Dragon
New Coder

 
Join Date: May 2008
Posts: 49
Thanks: 3
Thanked 0 Times in 0 Posts
Saint_Dragon is an unknown quantity at this point
Investment Form

Hey lads.

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) {

switch (number) {

if (answer == 'b')
alert("Correct Answer");

else

alert("Incorrect Answer");
)
********************************************************

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.
Saint_Dragon is offline   Reply With Quote
Old 05-07-2008, 10:26 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Sounds like homework!

Simple or compound interest? Annual, monthly or continuous compounding?
Philip M is offline   Reply With Quote
Old 05-07-2008, 11:07 AM   PM User | #3
Saint_Dragon
New Coder

 
Join Date: May 2008
Posts: 49
Thanks: 3
Thanked 0 Times in 0 Posts
Saint_Dragon is an unknown quantity at this point
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.

Last edited by Saint_Dragon; 05-07-2008 at 12:06 PM..
Saint_Dragon is offline   Reply With Quote
Old 05-07-2008, 11:14 AM   PM User | #4
rangana
Senior Coder

 
rangana's Avatar
 
Join Date: Feb 2008
Location: Cebu City, Philippines
Posts: 1,752
Thanks: 65
Thanked 372 Times in 365 Posts
rangana will become famous soon enoughrangana will become famous soon enough
Could you please include how the computation would work
__________________
Learn how to javascript at 02geek

The more you learn, the more you'll realize there's much more to learn
Ray.ph
rangana is offline   Reply With Quote
Old 05-07-2008, 12:23 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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>

I have no idea how

dunno(the answer) {
switch (number) {
if (answer == 'b')
alert("Correct Answer");
else
alert("Incorrect Answer");
)

is supposed to fit in.
Philip M is offline   Reply With Quote
Old 05-08-2008, 05:00 AM   PM User | #6
Saint_Dragon
New Coder

 
Join Date: May 2008
Posts: 49
Thanks: 3
Thanked 0 Times in 0 Posts
Saint_Dragon is an unknown quantity at this point
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..
Saint_Dragon is offline   Reply With Quote
Old 05-08-2008, 07:05 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 05-08-2008, 07:25 AM   PM User | #8
Saint_Dragon
New Coder

 
Join Date: May 2008
Posts: 49
Thanks: 3
Thanked 0 Times in 0 Posts
Saint_Dragon is an unknown quantity at this point
Quote:
Originally Posted by Philip M View Post
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
Saint_Dragon is offline   Reply With Quote
Old 05-08-2008, 07:29 AM   PM User | #9
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Saint_Dragon View Post
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.
Philip M is offline   Reply With Quote
Old 05-08-2008, 07:58 AM   PM User | #10
Saint_Dragon
New Coder

 
Join Date: May 2008
Posts: 49
Thanks: 3
Thanked 0 Times in 0 Posts
Saint_Dragon is an unknown quantity at this point
Thanks ive figured it out and its working.!

cheers.
Saint_Dragon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:48 PM.


Advertisement
Log in to turn off these ads.