Lesson 6
Strings, arrays, dates
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
- The page's script begins executing.
- The page has loaded.
- The user starts typing.
- The user types the last character.
- The user presses the button.
- The last character is loaded into its cell in the textual column of the table.