CIT 597 Assignment 3: Calculator
Fall 2007, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Implement, in JavaScript, a simple calculator.

Details:

Your calculator should look like this:

The calculator should work exactly like a "real" calculator, of the sort you can usually buy for under $5.

The buttons at the top have these meanings:

Computes the square root of the number in the display. Use the JavaScript Math.sqrt(x) method. Taking the square root of a negative number should yield Error in the display, and disallow any further work until is clicked.

Returns a pseudorandom number between 0.0 and 1.0. Use the JavaScript Math.random() method. The number returned can be used just as if the user simply entered it using the calculator buttons.

Clears the current entry, but does not clear any pending operation. For example, should give 14.

Clears everything--the display, any pending operator and operand, and any error.

Event handlers on calculator buttons should only call functions defined in the <head> element; they shouldn't do any work of their own.

Grading:

You can play around with shapes and colors and button arrangement, in order to give the calculator a more pleasing appearance, but I want exactly these buttons with exactly these meanings.

Due date:

Wednesday, October 3, before midnight. Put your calculator on a nice looking web page, and email the URL to both me and my grader.