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 7991395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:16:42+00:00 2026-06-04T13:16:42+00:00

I have made a fiddle: http://jsfiddle.net/csS24/ I’m trying to get the code to a

  • 0

I have made a fiddle:

http://jsfiddle.net/csS24/

I’m trying to get the code to a point, that it never ever shows the same two items at once or when one item is clicked, it never pulls back that same one from the array, just seem to be struggling a little with the logic and the indexOf method is behaving oddly.

var justAdded = [];
justAdded['first'] = 0;
justAdded['second'] = 1;

newHtml = returnRandom().split('|');

justAdded[e.id] = parseInt(newHtml[0], 10);

    if(justAdded.indexOf(parseInt(newHtml[0], 10)) == -1){
        e.style.opacity = 0;
        e.innerHTML = newHtml[1];
        e.style.opacity = 1;
        e.setAttribute('data-id', newHtml[0]);
    } else {
        uniq(clickedEl);
    }

var returnRandom = function(){
    return options[Math.floor(Math.random() * options.length)]
};

e.id will be equal to ‘first’ or ‘second’. returnRandom() will grab a random value from the options array:

var options = [
    '0|Flash',
    '1|Internet Explorer',
    '2|Java',
    '3|!important'
];
  • 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-04T13:16:44+00:00Added an answer on June 4, 2026 at 1:16 pm

    You seem to be adding non-numeric properties to an Array.

    The indexOf() method is intended to work on and return numeric properties.

    Furthermore…

    • the processAnswer handler passes the ID of the element to addHtml… like “first”, “second”

    • addHtml uses that ID string to grab the very same element stored in a variable with the same name, and then passes that element to uniq

    • uniq adds a property to the justAdded Array, with the key being the ID of the element.

    You keep switching between passing elements and their IDs, and using the one to get the other in every next function. All that is to say that your code seems terribly disorganized, and I think you just need to start from scratch and rethink your code.


    Also, what the heck is with this?…

    var options = [
        '0|Flash',
        '1|Internet Explorer',
        '2|Java',
        '3|!important'
    ];
    

    Why are you hardcoding indices into strings in the Array? Arrays are ordered lists. They already have the indices taken care of.

    var options = [
        'Flash',                // 0
        'Internet Explorer',    // 1
        'Java',                 // 2
        '!important'            // 3
    ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a quick fiddle to outline my problem: http://jsfiddle.net/mYdxw/ I'm trying to
I have made this fiddle: http://jsfiddle.net/4CtLV/ Now, what i'm trying to do, is if
I have made a fiddle: http://jsfiddle.net/89x4d/ I'm trying to maintain the skewed div but
I have made a quick fiddle: http://jsfiddle.net/tLLB4/ Ok, so the premise is, i'm hovering
I have made a Fiddle for reference: http://jsfiddle.net/xypQY/ Which element would i apply WebKit
I have made a fiddle: http://jsfiddle.net/hAzJq/ How can i select the text inside the
I made this fiddle http://jsfiddle.net/nAb6N/10/ As you can see I have 2 animators ,
I've got a dropdown I've made: http://jsfiddle.net/QPxVe/ For some reason, jsFiddle is altering the
http://jsfiddle.net/nicktheandroid/GPFxM/28/ I've also explained the situation in the JS Fiddle example. I binded hover
I have updated my code and made a fiddle which explains what I am

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.