Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:25:53+00:00 2026-06-18T05:25:53+00:00

I have created an string array, that hold 6 classes. The function is called

  • 0

I have created an string array, that hold 6 classes.
The function is called by a button, and for every click a new class i created.
the thing is that when i click the button, i get a randomize class, but if i press the button again. the same class is being displayed and not a random one. If i reload the page, an random class is generated, but as i said, the same class generates when i click again.

This is my random array.

   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);

    }
}

I paste the full function if the problem is there somewhere.

 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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:25:54+00:00Added an answer on June 18, 2026 at 5:25 am

    Just do the random thing every time the function is called, not outside of it:

    function addDiceEvent() {
        var rand = Array[Math.floor(Math.random() * Array.length)];
        dicesides_func(rand);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a function that will return the string path from my DB.
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I have created a servlet that passes a string variable strname to a JSP
Say I have a structure like: class SomeObject Public Name as String Public Created
I created a class Foo that has the method toArray() that returns an Array<Int>
I have an array that I have created to store error records and it
I am relatively new to Perl. I have a reference to an array called
I'm building a hashmap class that can have string keys and ints, bools, strings
I have an array of strings. The array was created by parsing a long
I have a string $string = 'S:1,M:1,L:1,XL:1,XXL:1,3XL:1'; I want to create an array where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.