Homework Assignment 1

Deadline: 7/2 (before class)

1. A calculator.

For this exercise you have to construct a web page with a basic calculator. The required features are:

  1. 10 buttons for the digits 0-9
  2. 4 buttons for the operations +,-,*,/
  3. a button for the = operation (which calculates the result)
  4. a clear button which clears the calculator
  5. a textbox where the data and results are written

The desired behavior is as follows: the textbox is readonly (it can only be manipulated using the buttons). As long as the user is pressing digits or operation buttons, the corresponding characters are added to the textbox. When the = button is pressed the contents of the textbox are replaced by the result of the expression (you probably want to use eval here). The clear button allows the user to start over.

Value: 5 points.

2. Tic-Tac-Toe.

For this exercise you must construct a web page that allows two users to play tic-tac-toe. The required features are:

  1. A 3x3 table that will represent the board.
  2. A reset button that clears the board.
  3. A check function that decides if a player has won.

The players will take turns placing their symbol on the board, with X playing first. The board should be interactive, that is, when a player clicks on a position that position should change to X or O, depending on whose turn it is. For better-looking results you may use images to represent the Xs and Os (this is not mandatory though). The game should not allow illegal moves (e.g. overwriting an opponent's symbol) and should be able to decide when someone has won. This can either be done automatically, after every move, or with a special "Check" button.

Value: 5 points.