I have 6 background images of dice numbers and want to select one at random. It works, but at random returns the error ‘in dice[diceRandom] (), ‘dice[diceRandom]’ is undefined. Could somebody help me -pointing out where I can learn it is fine, I’m not after free help. Cheers, Gareth.
let dice = [function six() {
document.getElementById("dicediv").style.background =
"url('dicesprite.png') 0, 0";
},
function five() {
document.getElementById("dicediv").style.background =
"url('dicesprite.png') -50px , 0";
},
/* .......... */
function one() {
document.getElementById("dicediv").style.background = "url('dicesprite.png') -100px , 0";
}
];
let diceRandom = Math.round(Math.random() * dice.length);
dice[diceRandom]();
<body>
<div id="dicediv"></div>
</body>
are just typos
– Gareth Evans Aug 19 '19 at 11:35