hajim urcs
Computer Science @ Rochester

DMS102/CSC170D: Introduction to Web Development
Spring 2013

Assignment 6: Functions

  1. [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.
  2. [4 pts] Write a page with a script that includes the following: 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.
  3. [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: 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.

  4. [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

Last update: Monday, 18-Mar-2013 10:39:05 EDT