Básicamente, mi problema es que estoy buscando obtener algunos datos de un objeto. El objeto se selecciona de una etiqueta html y la opción seleccionada se coloca en una función. La función maneja la obtención de los datos, pero arroja un error al intentar obtener la longitud de una matriz que se encuentra dentro del objeto. getRandInRange es una función que creé que funciona perfectamente, así que ese no es el problema.
Cuando ejecuto el código en el navegador, este es el error que obtengo
Uncaught TypeError: Cannot read properties of undefined (reading 'length') at buildHorde (app.js:46:60) at setValue (app.js:33:5) at HTMLInputElement.onclick (index.html:27:101) function buildHorde(obj,num){ // for every num add a random coin roll for (i = 0; i < num; i ++){ coinArr.push(obj.coins[getRandInRange(0, obj.coins.length-1)]); } // following lines add the new arrays into the html document. document.getElementById("coins").innerHTML = coinArr; return; } <p>Select Party Level: <select name="Party Level" id="getObj"> <option value=level1>level1</option> <option value=level2>level2</option> </select></p>Y este es el código para establecer los argumentos en la función.
function setValue(){ var select = document.getElementById('getObj'); obj = select.options[select.selectedIndex].value num = document.getElementById('getNum').value; buildHorde(obj,num); }objeto de nivel 1
let level1 = { coins: ["No coin", getRandInRange(1,6) * 1000 + " Copper Pieces ", getRandInRange(1,8) * 100 + " Silver Pieces ", getRandInRange(1,4) * 10 + " Platinum Pieces "], goods: ["nothing ", "Extravagant painting ", "ornate statue "], items: ["Boots of speed ", mundane.weapon[getRandInRange(0, mundane.weapon.length-1)], "Potion of fire breathing "], }