-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (48 loc) · 1.02 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Dice {
roll(maxValue, quantity=1) {
let values = []
for(let a = 0; a<quantity; a++) {
let randomValue = Math.round(Math.random() * (maxValue - 1)) + 1
values.push( randomValue )
}
return quantity > 1 ? values : values[0]
}
d4(quantity=1) {
return this.roll(4, quantity)
}
d6(quantity=1) {
return this.roll(6, quantity)
}
d8(quantity=1) {
return this.roll(8, quantity)
}
d10(quantity=1) {
return this.roll(10, quantity)
}
d12(quantity=1) {
return this.roll(12, quantity)
}
d20(quantity=1) {
return this.roll(20, quantity)
}
advantage() {
let values = this.d20(2);
let highest = values.sort(function(a, b){return b - a})[0]
return {
value: highest,
rolls: values
}
}
disadvantage() {
let values = this.d20(2);
let lowest = values.sort()[0]
return {
value: lowest,
rolls: values
}
}
percentage(quantity=1) {
return this.roll(100, quantity)
}
}
module.exports = new Dice()