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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:54:13+00:00 2026-06-03T03:54:13+00:00

I am currently creating a game that allows the user to click on numerous

  • 0

I am currently creating a game that allows the user to click on numerous amounts of images. Depending on which image they click, different things will happen. I have looked at previous questions and they all seem to ask “How do I randomly select an item inside an array”. However, mine is slightly different to these. Sorry if you feel that my answer lies somewhere else. But anyhow!

My question is simply:

How do I randomly select an array? My code so far contains a function that can check whether an integer exists within an array. This is my code so far.

//The array below contains the integers.
example=new Array(1,2,3);


//The function below checks whether 'image' (which is an integer) is the same as any integers within the example array.

function isItThere(obj) {
    var j = false;
    for (var i = 0; i < example.length; i++) {
        if (example[hits] == obj) {
            j = true;
            break;
        }
    }
    return j;
}
//This is the IF statement I have used. After the integer associated with 'image' has been passed through the 'isItThere' function either A or B will happen. (A happens if the number exists).
if(isItThere(image)){

Currently, this all works perfectly fine. Granted it might not be the most efficent way, but it achieves what I have so far wanted.

But I now want to have multiple arrays that contain integers. This is because if the user reloads the game then they know exactly which images to press for them to win. I am therefore wanting to create several arrays and one of which will be selected at random at the beginning of the game.

For example..

example0=new Array(1,2,3);
example1=new Array(4,5,6);
example2=new Array(7,8,9);

I believe I should be using the following code.

var num=Math.floor(Math.random()*3);

And then somehow link that number to the word ‘example’.

That way, this part of my code

if(isItThere(image)){

can stay the same, as it is the isItThere that deals with the choosing of a random array.

Hopefully you get what I’m trying to ask for. I have tried to be as descriptive as possible. To summarise once again, I want to be able to select one array at the beginning of the game so that the game can be played multiple times. Can you write the code I need? I have a feeling its very simple. But ive spent days looking.

Thanks for the help 🙂

  • 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-03T03:54:14+00:00Added an answer on June 3, 2026 at 3:54 am

    How about making a parent array and then referring to this parent array?

    var childArray1 = [1,2,3],
    childArray2 = [4,5,6],
    childArray3 = [7,8,9],
    parentArray = [childArray1, childArray2, childArray3];
    

    You can also add them with parentArray.push(childArray1); , just which one suits you better.

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

Sidebar

Related Questions

I am creating a game currently and I want users to be able to
I'm creating my first game, and I've currently set up a 'GameState' class, to
I am creating a simple tennis game in Objective-C. Currently, when the player or
I am currently creating a type of classifieds website, and when the user enters
I'm currently creating a user interface using WPF and would like to display a
I'm creating a game, and am currently working on the Inventory system for it.
Im trying to create a board game generator in ruby which takes images from
We're creating a game that will run on iOS, Android and in the web
I've got a medium scale project (a turn-based game) that's currently written in C/C++.
I am currently working on creating an import-based pipeline for my indie game using

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.