It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Need help with this script!

Need help with this script!

Postby Godwinrb on Fri Aug 01, 2008 5:47 pm

I can't get this script to perform a loop to calculate ten years of an output. Can someone tell me what I'm missing?

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

<!-- Exercise 8.8.html -->
<!-- Product for odd integers -->
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>Calculating compound interest</title>
<style type = "text/css">
table { width: 100% }
th { text-align: left }
</style>
<script type = "text/javascript">
<!--
var amount;
var principal = 1000.0;
var rate = .05



for ( var counter = 1; counter <= 10; ++rate )
document.writeln(
“<table border = \”1\”>” );
document.writeln(
“<caption>Calculating Compound Interest</caption>” );
document.writeln(
“<thead><tr><th>Year</th>” );


document.writeln( “</tr></thead><tbody>” );



<-- this for statement should be indented within the main one
for ( var year = 1; year <= 10; ++year )
rate = rate + .01;
{


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

}

document.writeln( "</tbody></table>" );






</script>
</head><body></body>
</html>
Godwinrb
 
Posts: 0
Joined: Fri Aug 01, 2008 5:42 pm

Postby rangana on Sat Aug 02, 2008 3:19 am

  • Your quotes are weird.
  • To comment in JS. You should use // for one line comment and /* */ for block comment.
  • What is your goal? You are having an infinite loop in your script. Also, you should be able to use DOM method for achieving this, though document.write() prove to be effective. It is deprecated and should be avoided.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines


Who is online

Users browsing this forum: No registered users and 3 guests