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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:14:12+00:00 2026-06-15T06:14:12+00:00

My code: I understand that my for loop assigns all array elements to the

  • 0

My code:

I understand that my for loop assigns all array elements to the variable pickSound and that is why I am left with it only playing the last element. So how can I get it to play each element in order and start over once done.

 function show() {
        var sounds = new Array(
            "audio/basement.mp3",
            "audio/roll.mp3",
            "audio/gatorade.mp3",
            "audio/half.mp3",
            "audio/hotdogs.mp3",
            "audio/keys.mp3",
            "audio/heil.mp3",
            "audio/money.mp3",
            "audio/ours.mp3",
            "audio/pass.mp3"
        );

        for (var i = 0; i < sounds.length; i++){
    var pickSound = sounds[i];     
        }

        $('#divOne').html("<embed src=\""+ pickSound +"\" hidden=\"true\" autostart=\"true\" />");
        return false;
    };
  • 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-15T06:14:13+00:00Added an answer on June 15, 2026 at 6:14 am

    ” I should have added that each click of the button plays a new sound. So a new sound can be played at any time.”

    I take it that means the sounds aren’t to be played continuously on an automatic loop. You intend for a click of a button to play whichever sound is next and then stop?

    In the following code the nextSound variable holds the index of whatever sound should be played next. When a button is clicked (insert your button’s ID or other selector as appropriate) the file name associated with that index is used and then nextSound is incremented using the modulus operator to loop back to zero when it gets to the end of the array.

    $(document).ready(function() {
       var sounds = ["audio/basement.mp3",
                     "audio/roll.mp3",
                     "audio/gatorade.mp3",
                     "audio/half.mp3",
                     "audio/hotdogs.mp3",
                     "audio/keys.mp3",
                     "audio/heil.mp3",
                     "audio/money.mp3",
                     "audio/ours.mp3",
                     "audio/pass.mp3"],
           nextSound = 0;
    
        $("#yourButtonIDHere").click(function() {
           $('#divOne').html("<embed src=\""+ sounds[nextSound] +"\" hidden=\"true\" autostart=\"true\" />");
           nextSound = (nextSound + 1) % sounds.length;
        });
    });
    

    Note also that it is generally recommend to declare arrays with the square bracket [] array literal syntax rather than new Array().

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

Sidebar

Related Questions

I'm trying to understand code that I bought so I can modify it. In
I understand that the code below would result segmentation fault because at the cstr
I understand that we can set the various style attributes from code behind using
So I understand that JSPs are a mixture of a client-side code (DHTML, JS,
I'm translating some C# code to Delphi, I understand that(msg = TMsg): (int)msg.LParam is
I understand the gist of the code, that it forms permutations; however, I was
i have some code that i am trying to recompile and understand, but i
I don't understand why authors said that Code Listing 9.1 from Programming in Scala
I have some legacy C++ code that I am trying to understand a bit
I've in inherited some code that I'm trying to understand and any searching I

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.