...

View Full Version : Stuck on tables



babylikesburgh
07-31-2008, 06:25 PM
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>

Mikebert4
07-31-2008, 06:29 PM
look at this bit of code



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


now look at this bit of 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 :p



The Mike.

babylikesburgh
07-31-2008, 06:38 PM
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!!!!!

Mikebert4
07-31-2008, 06:46 PM
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 ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum