Kir-Antipov/VanillaRoulette

Error Prize not found

Opened this issue · 1 comments

I used the minified JS and it worked perfectly, but when I tried to use the js from the 'src' folder I had this problem on the console: Uncaught Prize not found.

I'm checking and it seems that the problem is in the selectedPrize() getter


get selectedPrize() {
   console.log(this.prizes) // array 14 items prizes (ok!)
   let a = this.prizes
     .concat()
     .sort((c, a) => c.wrapper.offsetLeft - a.wrapper.offsetLeft)
     .find((a) => a.wrapper.offsetLeft > this.center).index

   console.log('AFTER', this.prizes[(this.prizes.length + a - 1) % this.prizes.length]) // CONSOLE LOG = rouletteJS.min.js?5ef7:110 Uncaught TypeError: Cannot read properties of undefined (reading 'index')

   return this.prizes[(this.prizes.length + a - 1) % this.prizes.length]
}

Hello, for those who will face a similar problem.
This error occurs if there are less than 10 elements in the roulette.
Just add another div inside id="rpulette" to have 10 or more.
How to run a roulette with less than 10 elements, I did not understand, because I have much more of them :)