I had recently learnt how to generate random numbers and I thought this code may be a good basis for a game. After some thought I decided to create a dice game; the aim being to roll either a 2 or a 6 in order to win. Very simple stuff.
Here is the code, including the XHTML framework, the CSS formatting and the Javascript to bring the game to life.

The die=Math.ceil(Math.random()*6); code generates a random number between 0 and 1, then multiplies it by 6, so we have a random number between 0 and 5.999. The Match.ceil part rounds this number up, so we have a random number between 1 and 6.
I then use an if statement to give the game different outcomes. So if the user rolls a 2 or a 6, they receive feedback telling them they have won. Otherwise, they are given the feedback 'sorry, try again'.
The try again text is a link, which also uses some Javascript. This javascript:location.reload(true) refreshes the page when clicked, so as to begin the whole cycle again.
The following screeshots show the sequence of the game.


