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 4 of 4

Thread: Stuck on tables

  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question Stuck on tables

    Yes, this is part of a homework problem. I've got it all except one error (obviously), so I'm certianly not asking for anyone to do this for me. However, in order for me to learn how to do this, I need to figure out how to get it right. Now, I need a new table to appear for each rate. When the code runs, it only shows the final table, not the others. I can about swear I have everything in the right place, but yeah... it's a no go. All I need is a suggestion or hint as to why my tables aren't all printing out. Thanks a bunch!

    <?xml version = "1.0" encoding = "utf-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


    <html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
    <title>Calculating Compound Interest</title>
    <style type = "text/css">
    table { width: 30% }
    th { text-align: left }
    </style>
    <script type = "text/javascript">
    <!--
    var amount; // current amount of money
    var principal = 1000.0; // principal amount
    var rate; // interest rate
    var counter; // keps track of each apr



    for ( counter = 5; counter <= 9; counter++ );
    {


    document.write(
    "<table border = \"1\">" ); // begin the table
    document.write(
    "<caption>Calculating Compound Interest</caption>" );
    document.write(
    "<thead><tr><th>Year</th>" ); // year column heading
    document.write(
    "<th>Amount on deposit</th>" ); // amount column heading
    document.write( "</tr></thead><tbody>" );



    // output a table row for each year
    for ( var year = 1; year <= 10; ++year )
    {
    rate = counter * .01;

    amount = principal * Math.pow( 1.0 + rate, year );
    document.writeln( "<tr><td>" + year +
    "</td><td>" + amount.toFixed(2) +
    "</td></tr>" );
    } //end for

    document.write( "</tbody></table><br />" );


    }

    // -->
    </script>
    </head><body></body>
    </html>

  • #2
    New Coder
    Join Date
    Jul 2008
    Location
    Peterborough - UK
    Posts
    63
    Thanks
    4
    Thanked 9 Times in 9 Posts
    look at this bit of code

    Code:
    for ( counter = 5; counter <= 9; counter++ );
    {
    now look at this bit of code

    Code:
    for ( var year = 1; year <= 10; ++year )
    {
    Where do they differ, and would that solve your problem?


    there's somthing I personally wouldn't do (define a variable in a for() expression) - but thats not the big whoopsie



    The Mike.
    Last edited by Mikebert4; 07-31-2008 at 06:31 PM.

  • Users who have thanked Mikebert4 for this post:

    babylikesburgh (07-31-2008)

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    7
    Thanked 0 Times in 0 Posts
    The Mike:

    Awesome!!!!! This is why I get anxious about scripting, one little mistype (I seem to get in the groove of throwing in those semicolons!) and the whole thing malfunctions. Thank you so much for calling that out for me. Sadly I didn't catch it at first, I switched counter++ to ++counter, lol... My brain is warped from so much coding over the past 2 days ^_^

    Thanks again!!!!!

  • #4
    New Coder
    Join Date
    Jul 2008
    Location
    Peterborough - UK
    Posts
    63
    Thanks
    4
    Thanked 9 Times in 9 Posts
    Hehe, we've all been there..

    I'm doing the exact same thing in Php at the moment *sighs* only difference is, typos cost me money (talk about an incentive!).

    It gets even better when they go and change a standard on you (i'm looking at you '[]', bring back 'new Array()'!).

    Good luck, and I'll be lurking if you get stuck on anything else


  •  

    Posting Permissions

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