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

  • SEARCH
  • Home
  • 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 8877323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:26:29+00:00 2026-06-14T19:26:29+00:00

I am writing a script that onload will add a class to a random

  • 0

I am writing a script that onload will add a class to a random 4 of 12 DIV’s and then remove the ID of the DIV from the array.

I have an array setup with all 12 DIV ID’s in it.

Sometimes when I reload the page, 4 DIV’S have that class and other times only 3 DIV’s have that class.

Kinda stuck on why this is happening. I commented out the remove from array code to see if that was the issue, but still same problem.

Here is my code:

//Randomize Which Shoes Are Positive And Negative
function randomizeShoes(){
    allGroundShoes = new Array('ground_black_1','ground_black_2','ground_brown_1','ground_brown_2','ground_clown_1','ground_clown_2','ground_disco_1','ground_disco_2','ground_moccasins_1','ground_moccasins_2','ground_red_1','ground_red_2');
    for(var i=0; i < 4; i++){
        randomAllGroundShoes = allGroundShoes[Math.floor(Math.random() * allGroundShoes.length)];
        $('#'+randomAllGroundShoes+'').addClass('shoeNegitive');
        //randomShoeID = allGroundShoes.indexOf('randomAllGroundShoes');
        //if(randomShoeID != -1){ allGroundShoes.splice(randomShoeID, 1); }
    }
}
  • 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-14T19:26:30+00:00Added an answer on June 14, 2026 at 7:26 pm

    When you remove the found element, you are passing in a string literal instead of the variable name:

    allGroundShoes.indexOf('randomAllGroundShoes');
    

    Since there is no element 'randomAllGroundShoes', the element would never be found, and no elements would ever be removed from the array.

    It should be:

    allGroundShoes.indexOf(randomAllGroundShoes);
    

    But, you are doing the same thing more than once. You don’t need to check allGroundShoes.indexOf() at all. You could just store the random number in a variable and reference it again. But, even that is more than you need. Just call splice() to get your value:

    randomAllGroundShoes = allGroundShoes.splice(
        Math.floor(Math.random() * allGroundShoes.length), 1)[0];
    $('#'+randomAllGroundShoes).addClass('shoeNegitive');
    

    This way, you retrieve your value and remove it from the array in one step – no additional lookup required.

    jsfiddle.net/kRNTg

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a script that will ping my ip range. Here's what I have
I'm writing a script that will grab several files and then copy them into
I'm currently writing a script that grabs a file from a website and then
I'm writing a script that will combine and minify requested CSS files and then
I'm writing a script that will constantly scan iTunes for new dialog boxes and
I'm writing a script that asks the user for several options and then, via
I am writing a script that will look in a custom reports directory, copy
I am writing a script that is retrieving information from file places.sqlite (history) and
I'm writing a script that will install some of the optional postgresql modules. Is
i have this script below that will resize the .content on window resize it

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.