Code missing something

##################

Generative Art

- Generating your NFT collection

##################


Mutating 0 of 100

  • rarity: undefined
    C:\Users\brans\Documents\2d game\Pixel people\index.js:145
    Math.random() * layer.elementIdsForRarity[_rarity].length
    ^

TypeError: Cannot read properties of undefined (reading ‘length’)
at C:\Users\brans\Documents\2d game\Pixel people\index.js:145:58
at Array.forEach ()
at createDna (C:\Users\brans\Documents\2d game\Pixel people\index.js:143:11)
at saveFile (C:\Users\brans\Documents\2d game\Pixel people\index.js:328:20)
at handleFinal (C:\Users\brans\Documents\2d game\Pixel people\index.js:390:31)
at startCreating (C:\Users\brans\Documents\2d game\Pixel people\index.js:393:11)
at Object. (C:\Users\brans\Documents\2d game\Pixel people\index.js:453:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions…js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47

this would mean that this is undefined

right so then how do i define it i guess i thought i did here

const getRandomRarity = (_rarityOptions) => {
  let randomPercent = Math.random() * 100;
  let percentCount = 0

that seems to be an array, dat doesn’t have data for a particular _rarity

i see hmm im not sure how to fix it ill have to play around i guess

I was stuck in the same error and my solution was to add “?” to avoid undefined error

percentCount += _rarityOptions[i]?.percent;