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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:45:54+00:00 2026-05-26T04:45:54+00:00

I am lost in this error. I am trying to write a function and

  • 0

I am lost in this error. I am trying to write a function and write a array in that function. in an external js file. This is going to be a random image loading function but i keep getting an error with the array and can’t figure out why.

function  randImg(){
    var imgs = new Array(); 
    img[0]="banner1.png";
    img[1]="banner2.png";
    img[2]="banner3.png";
    var maxium = img.length;
}

I am getting the error on the var imgs line. any ideas?

Here is my new code calling the variable “img” was throwing me off it loads ok but it only prints out the text in the variable and not the actually file!? so at run it say “banner1.png” or “banner3.png”? any thoughts

function randImg(){
var banner = new Array();
banner[0] = "banner1.png";
banner[1] = "banner2.png";
banner[2] = "banner3.png";
var maxImg = banner.length;
var randNum = Math.floor(Math.random()*maxImg);
return banner[randNum];
}
  • 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-05-26T04:45:55+00:00Added an answer on May 26, 2026 at 4:45 am

    A better way to define the array with its elements:

    var img = [
          "banner1.png",
          "banner2.png",
          "banner3.png",
          "banner4.png"
    ]
    

    And this is the function you might need:

    function randImg(){
        var img = [
              "banner1.png",
              "banner2.png",
              "banner3.png",
              "banner4.png"
        ]
        var maxImg = img.length;
        var randNum = Math.floor(Math.random()*maxImg)
        return img[randNum]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to find a way to match this problem but i'm LOST i
I am trying to error check a form that on submitting creates an array,
I am trying to write a program using python-fuse, but I can't get file
Hi this is pretty basic jQuery stuff but i am a little lost. So
This is probably something silly I'm missing but I'm definitely lost. I'm using .NET
This is probably really easy, but I'm lost on how to make sure it
I'm trying to write a secure transfer file program using Python and AES and
I'm trying to make a Preview function. I'm reading this blog, Django Admin Preview
I'm trying to build an object that looks something like this: public class MyObject
I am so lost on this. I am trying to use the publishUserAction feature

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.