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

Thread: Investment Form

  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Sounds like homework!

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

  • #3
    New Coder
    Join Date
    May 2008
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    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

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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

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

    is supposed to fit in.

  • #6
    New Coder
    Join Date
    May 2008
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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>
    Last edited by Saint_Dragon; 05-08-2008 at 07:09 AM.

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.

  • #8
    New Coder
    Join Date
    May 2008
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,082
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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.

  • #10
    New Coder
    Join Date
    May 2008
    Posts
    49
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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
    •