[an error occurred while processing this directive]
File: index.shtml
Creator: George Ferguson
Created: Mon Oct 15 13:24:55 2012
Time-stamp:
[an error occurred while processing this directive]
File: templates/doc-start.shtml
Creator: George Ferguson
Created: Tue Dec 6 12:31:29 2011
Time-stamp:
[an error occurred while processing this directive]
File: site-settings.shtml
Creator: George Ferguson
Created: Tue Dec 6 13:49:49 2011
Time-stamp:
Site (or subsite)-wide settings.
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
File: head.shtml
Creator: George Ferguson
Created: Tue Dec 6 12:34:15 2011
Time-stamp:
SSI variables for this template:
head_title if given, else ``sitename | title''
[an error occurred while processing this directive]
File: head-title.shtml
Creator: George Ferguson
Created: Tue Dec 6 14:29:52 2011
Time-stamp:
SSI variables for this template:
head_title: complete content of title element if given
site_title trailing part of title (if given)
section_title middle part of title (if given)
page_title leading part of title (if given)
title title shown on page, also used as leading part of title (if given)
[an error occurred while processing this directive]
(none)
[an error occurred while processing this directive]
File: head-meta.shtml
Creator: George Ferguson
Created: Tue Dec 6 14:29:18 2011
Time-stamp:
SSI variables for this template:
meta_description
meta_keywords
meta_generator
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
File: head-stylesheets.shtml
Creator: George Ferguson
Created: Tue Dec 6 14:22:58 2011
Time-stamp:
SSI variables for this template:
site_stylesheet, page_stylesheet
stylesheet0, stylesheet1, ...: URL for stylesheets
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
File: head-scripts.shtml
Creator: George Ferguson
Created: Tue Dec 6 14:23:19 2011
Time-stamp:
SSI variables for this template:
site_script, page_script
script0, script1, ...: URLs of javascript scripts
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
[an error occurred while processing this directive]
File: body-start.shtml
Creator: George Ferguson
Created: Tue Dec 6 13:20:46 2011
Time-stamp:
SSI variables for this template:
body_class
page_class
page_id
[an error occurred while processing this directive]
[an error occurred while processing this directive]
File: body-header.shtml
Creator: George Ferguson
Created: Tue Dec 6 13:46:12 2011
Time-stamp:
Content above banner, if any.
[an error occurred while processing this directive]
File: body-title.shtml
Creator: George Ferguson
Created: Tue Dec 6 14:34:49 2011
Time-stamp:
SSI variables for this template:
section_name First line of title on page (if any)
title Title shown on page
[an error occurred while processing this directive]
DMS102/CSC170D: Introduction to Web Development Spring 2013
[an error occurred while processing this directive]
Assignment 6: Functions
[2 pts]
Write a function that takes three arguments and returns their mean
(average). Use your function in a page that repeatedly asks the user
for three numbers and then prints the numbers and their mean. Choose
your own stopping condition (sentinel) and make it clear in your
prompt.
[4 pts]
Write a page with a script that includes the following:
A function named writeTableCell that accepts a
single parameter and outputs a table cell containing the
parameter's value to the page's document.
A function named writeTableRow that accepts 3
parameters and outputs a table row with the 3 values as
separate cells.
The script should use these functions to produce a table for values
from 1 to 10 containing the value, the value squared, and the value
cubed. That is, for row i, the columns should
contain i, i2, and i3.
[4 pts]
You're hired by a financial company to spiff up their webpages.
First write a function named 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:
Initial sum
Interest rate
Number of years
It should return the future value of the initial amount if
invested for the given number of years at the given interest rate
compounded annually. Don't look it up on the web. Think what this
means and the way to write the function will be obvious to
you. How much will you have after one year? Then what happens to
that the second year? And so on.
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.
[2 pts]
Consider the following script:
// 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).
Things to think about
Every function you define should come with a comment that explains
its purpose (briefly), its arguments, and its return value. Not
only will the TAs be checking for this in your submission, it's
also the Right Thing To Do.
It is important when defining functions to use meaningful names
for both the function and the arguments. This helps immensely in
understanding the code. You can
use CamelCase
or, for a somewhat more retro
look, underscores
for your names.
Does it matter where in your script the functions are defined,
relative to where they are called? Could they be defined in a
separate script element or linked script? Experiment.
Variable scoping problems are the source of many, many Javascript
errors. Be very careful with variable declarations
(var statements) to minimize problems.
[an error occurred while processing this directive]
File: doc-finish.shtml
Creator: George Ferguson
Created: Tue Dec 6 13:46:48 2011
Time-stamp:
[an error occurred while processing this directive]
File: body-footer.shtml
Creator: George Ferguson
Created: Tue Dec 6 14:43:56 2011
Time-stamp:
Content at bottom of page, if any.
Last update: Monday, 18-Mar-2013 10:39:05 EDT
[an error occurred while processing this directive]
File: body-finish.shtml
Creator: George Ferguson
Created: Tue Dec 6 13:47:36 2011
Time-stamp:
[an error occurred while processing this directive]