writeTableCell that accepts a
single parameter and outputs a table cell containing the
parameter's value to the page's document.
writeTableRow that accepts 3
parameters and outputs a table row with the 3 values as
separate cells.
futureValue that
computes how much a
given initial sum of money will be worth after a period of time with
compound interest (meaning you reinvest the interest). Your
function should accept the following three parameters:
Use your function in a page that asks a user for the initial sum of money, and prints a table with the future value at 1%, 3%, and 5% return for 1, 5, and 10 years each. That is, the rows of the table are the different interest rates, the columns are the different terms, and each cell in the table contains the future value of the initial sum for the corresponding rate and term.
// Global variables
var count = 0;
var total= 0;
// myfunc: Do something funcky...
function myfunc() {
var count = 0;
count += 1;
var n = parseInt(window.prompt("Enter a number"));
total += n;
document.write("<p>");
document.write("count=" + count + ", total=" + total);
document.write("</p>");
}
// Main program starts
myfunc();
count = 10;
myfunc();
total = 42;
myfunc();
Copy the code into a script element in a document. Run it (load
the page). Then add a paragraph to the document explaining the
behavior of the program (that is, why it output what it did).
script element or linked script? Experiment.
var statements) to minimize problems.
Last update: Monday, 18-Mar-2013 10:39:05 EDT