↑
Games >>>
Next time you play a game involving dice, give this JavaScript Dice Roller a try! Just tell it how many dice to use, how many sides are on each die, and it'll give you the total for the number of dice you rolled!
Add the below code to the <body> section of your page:
<script
language= "javascript"
type= "text/javascript" >
var
die =
6 ;
var
dice =
3 ;
function
dice_roll ( die ,
dice )
{
var
roll =
0 ;
for
( loop = 0 ;
loop
<
dice ;
loop ++)
{
roll
=
roll +
Math . round ( Math . random ()
*
die )
%
die +
1 ;
}
document . form . text . value
=
roll ;
}
</script>
< center >
<form
name= form >
<table
border= 2
cellpadding= 5 >
<tr>
<td
colspan= 2
align= middle > What
dice type? </td>
<td
colspan= 2
align= middle > How
many dice to roll? </td>
</tr>
<tr>
<td
valign= top
align= middle >
< br > <input
type= radio
name= sides
onclick = "die
= 3" > 3
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 4" > 4
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 5" > 5
Sided
< br > <input
type= radio
checked
name= sides
onclick = "die
= 6" > 6
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 8" > 8
Sided
</td>
<td
valign= top
align= middle >
< br > <input
type= radio
name= sides
onclick = "die
= 10" > 10
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 12" > 12
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 20" > 20
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 30" > 30
Sided
< br > <input
type= radio
name= sides
onclick = "die
= 100" > 100
Sided
</td>
<td
valign= top
align= middle >
< br > <input
type= radio
name= number
onclick = "dice
= 1" > 1
< br > <input
type= radio
name= number
onclick = "dice
= 2" > 2
< br > <input
type= radio
checked
name= number
onclick = "dice
= 3" > 3
< br > <input
type= radio
name= number
onclick = "dice
= 4" > 4
< br > <input
type= radio
name= number
onclick = "dice
= 5" > 5
</td>
<td
valign= top
align= middle >
< br > <input
type= radio
name= number
onclick = "dice
= 6" > 6
< br > <input
type= radio
name= number
onclick = "dice
= 7" > 7
< br > <input
type= radio
name= number
onclick = "dice
= 8" > 8
< br > <input
type= radio
name= number
onclick = "dice
= 9" > 9
< br > <input
type= radio
name= number
onclick = "dice
= 10" > 10
</td>
</tr>
<tr>
<td
align= middle
colspan= 4 >
<input
type= button
value= "Roll
Dice"
name= button
onclick = "dice_roll(die,
dice)" >
<input
type= text
size= 10
name= text >
</td>
</tr>
</table>
</form>
< /center >
→