/    Sign up×
Community /Pin to ProfileBookmark

Multidimensional Arrays help

[U]What the program does[/U]

  • 1.

    The program will ask for a track number from the auxillary function “trackNumber()”

  • 2.

    It will then ask in the function “insert(trackNumber)” to enter the data for that track number.

  • 3.

    Finally, when all data has been entered, it will display that data via the alert statement

  • [U]The Problem[/U]

    When It asks to enter the data, I am only able to enter one value, before it asks for another track number.

    [U]The Code[/U]

    [code=php]
    insert(trackNumber)

    function trackNumber()
    {
    var theNumber = eval(prompt(“Enter Track Number”));
    if ((theNumber >= 0) && (theNumber < 100))
    {
    return theNumber; // Stores the track number for insert(trackNumber)
    }
    }

    function insert(trackNumber)
    {
    // Create new Array
    var musCollect = new Array(5);

    // For each Track we want to hold the trackNumber(), the track name and the track’s artist.
    for(var x = 0; x < musCollect.length; x++)
    {
    musCollect[x] = new Array(2);
    for(var y = 0; y < musCollect[x].length; y++)
    {
    musCollect[x][y] = prompt(“Enter data ” + y + “nFor track ” + trackNumber() + “n 0 – Track Name, 1 Track Artist”);
    }
    }

    var collectInfo;
    for(var i = 0; i < musCollect.length; i++)
    {
    collectInfo = “”;
    for(var j = 0; j < musCollect[i].length; j++)
    {
    collectInfo = collectInfo + “n ” + musCollect[i][j]
    }
    alert(collectInfo);
    }
    }[/code]

    So how could I get the program to input all the data before it ask’s for another track number?

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @A1ien51Dec 06.2009 — Do not use eval() it is evil()

    You should use parseint(myVar,10) or parseFloat(myVar) to convert a string to a number.

    Why are you not returning anything if it is not in that range? You should return something so you know exactly how your script runs.

    Why are you calling a prompt inside of a prompt?

    Eric
    ×

    Success!

    Help @DarkDragons spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.28,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...