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.
1 Odpowiedź
+ 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)