I have created a string array that holds 6 different classes. Whenever I click a button, a new class is generated randomly. However, the issue arises when I click the button again and get the same class instead of a new random one. Even after reloading the page, the same class is displayed upon clicking again.
Below is my array containing the classes:
var Array=["dice dice-side-one",
"dice dice-side-two",
"dice dice-side-three",
"dice dice-side-four",
"dice dice-side-five",
"dice dice-side-six",
"dice dice-side-six"];
var rand = Array[Math.floor(Math.random() * Array.length)];
function addDiceEvent() {
dicesides_func(rand);
}
In case the problem lies within the function itself, here is the complete code:
function AddEvent(){
var AddEvent = "add";
var addClassArr= document.getElementsByClassName(AddEvent);
for(var i=0; i<addClassArr.length; i++){
var addClass = addClassArr[i];
addClass.addEventListener("click", addDiceEvent, true);
}
var Array=["dice dice-side-one",
"dice dice-side-two",
"dice dice-side-three",
"dice dice-side-four",
"dice dice-side-five",
"dice dice-side-six",
"dice dice-side-six"];
var rand = Array[Math.floor(Math.random() * Array.length)];
function addDiceEvent() {
dicesides_func(rand);
}
}
AddEvent();