HTML and CSS Reference
In-Depth Information
Code
Explanation
<button onClick="throwdice();">Throw
dice </button>
Button element (note attribute
onClick
setting
to invoke
throwdice
)
</body>
Close body tag
</html>
Close html tag
The complete game of craps
The third application is the complete game of craps. Again, much can be carried over from the previous
application. However, now we need to add in the rules of the game. Among other things, this will mean
using the conditional statements
if
and
switch,
as well as global variables, that is variables defined
outside of any function definition, to keep track of whether or not it is a first turn (
firstturn
) and what is
the player's point (
point
). The function table is identical to the one given for the second application (Table
2-3), so I won't repeat it. Table 2-5 holds the code for this application. The new action is all in the
throwdice
function. I will comment the new lines.
Table 2-5.
The Complete Craps Application
Code
Explanation
<html>
<head>
<title>Craps game</title>
<script>
var cwidth = 400;
var cheight = 300;
var dicex = 50;
var dicey = 50;
var dicewidth = 100;
var diceheight = 100;
var dotrad = 6;