CS 101 - Introduction to Computing, Spring 2008

Project 2 - A JavaScript Calculator

Due Date: Tursday 3/13/2008 at 11:59 pm

We want to use JavaScript to create a simple calculator. The calculator would have a single display that will change based on the buttons pressed by the user. The calculator should have buttons for the following:

In class on 2/28/08, we discussed that the +/- sign button could be just a - sign. Most calculators do have a +/- sign. The original write up for this program did mention the +/- sign. The operation of the +/- sign would change the sign of the value in the display everytime the button is pressed (from positive to negative or from negative to positive). The operation of the - sign would only allow the changing of a positive number into a negative number.

The decimal point should only function if the value in the display is currently a whole number (an integer/no fractional part).

If the display currently displays the value of zero as a whole number (an integer/no fractional part) and another digit is pressed, the display should only show the value of the digit that was pressed. In other words, a non-zero whole number should never have leading zeroes and a the value of zero should only be represented with a single zero digit.

When one of the operation buttons are pressed (addition, subtraction, multiplication or division), the calculator needs to remember the current value in the display and which operation was pressed. Thus when the equal sign is pressed it can display the result of:

     storedValue storedOperation displayValue
Thus if the user presses the multiplication button while the display have the value of 212 and then the user pressed the equal sign while the display has the value of 4 (assume the user entered the value of 4 after pressing the multiplcation button and before pressing the equal sign), the calculator will display the result of
     212   *   4
or 848.

When one of the operation buttons are pressed, the display should show the same value as was shown prior to pressing the operation button. The first digit press after an operation button is pressed should replace the display with the value of the digit that was pressed. The same should occur for the first digit press after the equal sign in pressed. If the decimal point is the first button pressed after a operation button or the equal sign, the display should contain the zero digit followed by the decimal point.

Note that JavaScript always left justifies output in a text field. That is fine for this project. Also, the project only defines how the text field changes when the buttons are pressed. If the user types text into the text field, your program does not have to handle that in any predetermined manner (i.e. whatever happens, happens).

Project Collaboration

You are allowed to receive help on this project from other students who are also taking CS 101. Each student must still complete and submit his/her own project. You will be required to include a Collaboration Statement somewhere on your project if you receive help. This statement can simply be something like the following:
For this project, I received help from the following member of CS 101.
This statement should list each helping student's name with a link to that person's CS Homepage. This statement DOES NOT count toward the completion of any technical requirements for this project.

Submission of your Project

In addition to displaying your weblet on the inernet, you must electronically submit all of your files (all .html files, all image files and any other files used with your weblet) via the UNIX turnin command using the project name of proj2.

The easiest way to submit the UNIX turnin command, is to create a directory that contains all of the files needed for your information web. Then you turnin the entire directory. For example, assume you create a subdirectory in your WWW directory called proj2directory. In this "proj2directory" directory you contain all of the files needed for this assignment. If you are in your WWW directory, you can the type in the command:

    $> turnin -c cs101 -p proj2 proj2directory
To verify what you submitted using the turnin command type:
    $> turnin -c cs101 -p proj2 -v

CS 101 Home Page
Department of Computer Science
University of Illinois at Chicago