0

I try to make a xd6 roller for warhammer. P.s. I just started to code

Well I have this code. function roll(n){ var a = Array(n); for (var i = 0; i < n; i++) a[i] = Math.floor(Math.random() * 6) + 1; a= a.sort(( a , b) => a - b); return a[i]; } console.log(roll(6)); But it’s getting a null if I try to roll 6 d 6. I also want to sort them from low to hige.

22nd Jan 2021, 9:57 PM
Martijn Greven
1 Réponse
+ 1
you need to return whole array, not the necessarly undefined a[i] (after loop, i hold the array length, wich is the first undefined index)
22nd Jan 2021, 10:11 PM
visph
visph - avatar