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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:31:50+00:00 2026-06-07T06:31:50+00:00

The goal of the following code is to create a 2d array such that

  • 0

The goal of the following code is to create a 2d array such that

  • Clip is a custom object
  • a Bank is an array of (8) clips
  • Banks is an array of (8) banks
  • Each clip is accessible by banks[a][b], where a is an index in banks (a bank) and b is an index in clips (a clip)

In its current state it returns undefined, alas I am at a loss to explain why. Any suggestions about what I’m doing wrong would be greatly appreciated

var banks = []

function Clip(a,b)

{
this.track = a
this.slot = b
}

function Bank(w)

{

for (var j, j = 0; j <= 7; j++) {
    var clips = []
    var aClip = new Clip(w,j);
    //post(i)
    //post(aClip.length)
    clips[j] = aClip
}
//post();
return clips
}

function makeBanks()

{

for (var k, k = 0; k <= 7; k++) {
    var aBank = Bank(k);
    //post(i)
    //post (aClip.length)
    banks[k] = aBank
}
}

makeBanks();

console.log(banks[0][0])​

Many thanks in advance

  • 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-07T06:31:51+00:00Added an answer on June 7, 2026 at 6:31 am

    Your biggest mistake is here (inside Bank):

    for (var j, j = 0; j <= 7; j++) {
        var clips = []
        var aClip = new Clip(w,j);
        //post(i)
        //post(aClip.length)
        clips[j] = aClip
    }
    

    You’re re-initializing clips each time through the loop, so that the only value that is retained is the last one (since the loop terminates before you get a chance to overwrite it again). To illustrate, this is what’s returned from the first call to Bank:

    [undefined, undefined, undefined, undefined, undefined, 
         undefined, undefined, Clip { track=0, slot=7}]
    

    Moving the declaration outside of the loop solves this basic problem:

    var clips = [];
    for (var j = 0; j <= 7; j++) {
        var aClip = new Clip(w, j);
        clips[j] = aClip;
    }
    return clips;
    

    Additional Clean-up

    Now that we’ve solved the basic problem, there’s a lot more we could do to clean this up:

    • Use semi-colons consistently
    • Don’t name functions with an initial uppercase letter unless you intend to use them as constructors
    • Indent consistently
    • Don’t rely on global variables
    • Declare and assign in one step (i.e. var j, j = 0 should be var j = 0)

    The result:

    function Clip(a, b) {
        this.track = a;
        this.slot = b;
    }
    
    function makeBank(w) {
        var clips = [];
        for (var j = 0; j <= 7; j++) {
            var aClip = new Clip(w, j);
            clips[j] = aClip;
        }
        return clips;
    }
    
    function makeBanks() {
        var banks = [];
        for (var k = 0; k <= 7; k++) {
            var aBank = makeBank(k);
            banks[k] = aBank;
        }
        return banks;
    }
    
    var banks = makeBanks();
    console.log(banks[0][0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The goal of the following code sample is to read the contents of $target
I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
Does the following psuedo code accomplish my goal of cleaning up after myself when
I have the following database table object: public class Goal { @DatabaseField(generatedId = true)
My ultimate goal is to create an eclipse plugin that sets up a PDT
My goal is to create an animation with the YUI Animation Utility that does
I'm using the following code in an ASP.NET page to create a record, then
I have to create object model for following XMLs: XML sample 1: <InvoiceAdd> <TxnDate>2009-01-21</TxnDate>
I have following goal: From a list in main activity that extends ListActivity, I
My goal in the following is to have a Popover appear via one of

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.