-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrolling_dice.js
29 lines (25 loc) · 982 Bytes
/
rolling_dice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var j=1;
function rollDice()
{
var numberRoll = document.getElementById('number').value.match(/^\d+$/);
var type_dice = document.getElementById('type').value.match(/^\d+$/);
var result = document.getElementById('result');
if (numberRoll == null || type_dice == null) {
alert('The fields require numbers, you fool !');
} else {
result.innerHTML += "Result of dice 1: ";
for(var i = 0; i < numberRoll; i++) {
// Make dah roll !
var roll = 1+Math.floor(Math.random()*type_dice);
// Display the result
result.innerHTML += roll + " ";
}
result.innerHTML += "<br />";
}
}
function addDice()
{
j++;
document.getElementById('addDice').innerHTML+="<label>Type of dice "+j+":</label> <span id='increment'></span><input type='text' id='type' /><br />";
document.getElementById('addRoll').innerHTML += "<label>Number of roll, dice "+j+":</label> <span id='addRoll'></span><input type='text' id='number' /><br />";
}