Lesson 6
Strings, arrays, dates

Elementary string handling

Arrays of things

Time


Exercise #6

Create a page containing pictures of two dice: one labeled "fair" the other labeled "biased". When the user clicks on the fair die, its picture is replaced with a random one of six possible pictures -- each chosen with equal probability (1/6). When the "biased" die is clicked, it also is "rolled" but with unequal probabilities for the 6 faces, with higher numbers having higher probabilities. Specifically, for i between 1 and 6, P(i)=i/21. (Note that 1+2+3+4+5+6=21).

Results of the dice rolls should be kept in a textarea at the bottom of the page. A button below that text area, should allow the user to obtain a report (perhaps overwriting the text area) which tabulates the frequency of each of the six outcomes plotted separately for each of the dice.

You may use the template shown here, but design your own dice.


Exercise #7: Make a page (using this template, if you like) which

  1. allows the user to enter a string of up to 10 characters and then press a button
  2. when the button is pressed, the 10 characters are moved (and arranged vertically) into ten cells which comprise one column of a table.
  3. calculates the elapsed time between each pair of several successive events:
  1. The page's script begins executing.
  2. The page has loaded.
  3. The user starts typing.
  4. The user types the last character.
  5. The user presses the button.
  6. The last character is loaded into its cell in the textual column of the table.