CCSF Spring 2010 / CNIT 133 Homework 5 - Functions


Link to... Description
Part 1 This is a webpage that contains a script, that uses a function to manage a form of three text boxes. The first text box will be input of a circle's radius and the other two text boxes output the area and circumference of the circle. The function should be triggered by a form button.

Use the the math constant Math.PI for the constant PI.

area = PI*radius2
circumference = 2*PI*radius

Round the results to 2 decimal places. Be sure to test for a non-numeric value entered by the user and if so, then alert "Please input a numeric value".
Part 2 This is a webpage that contains a script that:
  1. Contains the function celsius, that returns the Celsius equivalent of a Fahrenheit temperature, using the calculation:

    C = 5/9 * (F - 32)
  2. Contains the function fahrenheit that returns the Fahrenheit equivalent of a Celsius temperature, using the calculation:

    F = 9/5 * C + 32
Use these functions to write a script that enables the user to enter either a Fahrenheit or a Celsius temperature and displays the Celsius or Fahrenheit equivalent.

Your XHTML document should contain two form buttons - one to initiate the conversion from Fahrenheit to Celsius and one to initiate the conversion from Celsius to Fahrenheit.
Part 3 Create a webpage containing a script that will determine whether a department-store customer has exceeded the credit limit on their charge account.

For input, the following facts should be available in form input text boxes:
  1. Account number
  2. Balance at the beginning of the month
  3. Total of all items charged by this customer this month
  4. Total of all credits applied to this customer's account this month
  5. Allowed credit limit
Validate whether the account number has been entered and that the amount items are numeric.

Calculate the new balance (which equals beginning balance + charges – credits), and determine whether the new balance exceeds the customer's credit limit and by how much.

Then display in a form textarea, the new balance and whether the customer has exceeded their credit limit and by how much, by displaying the message “Credit limit exceeded by X”, where X is the amount the credit limit was exceeded.

If the customer is at or under their credit limit then display their new balance and the message "Credit available is X", where X is the amount of their available credit.
Part 4 Computers are playing an increasing role in education. Write a webpage that will help an elementary school student learn multiplication. Use Math.random to produce two positive one-digit integers (0-9). It should then display a question such as:

How much is 6 times 7 ?

The student then types the answer into a text field. Your programming checks the student's answer. If it is correct, display the string "Very good!" in an alert, and then prompt the user to see whether they wish to continue by using the confirm statement. If true, then generate a new question. If not, then exit the script.

If the answer to the multiplication question is wrong, display the string "No. Please try again." in an alert, and let the student try the same question again repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the script begins execution and each time the user answers the question correctly.


Valid XHTML 1.0 Strict Valid CSS!