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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:58:12+00:00 2026-05-28T05:58:12+00:00

I’m working on creating a fireworks show in javascript for my last day of

  • 0

I’m working on creating a fireworks show in javascript for my last day of work tomorrow and I’m having some trouble getting it to automate. I’m using the fireworks found here and it works great, but this is going to be on a status webpage that I developed a while ago so I want the fireworks to be automatic instead of on click.

I’ve created a function on the fireworks.js page that looks like this…

function fireFireworks(){
    var num = Math.floor(Math.random()*3) + 1;
    for(i=0;i<num;i++){
        createFirework();
    }
}

This will be used to fire between 1 and 3 fireworks when it’s called. Then I setup

setInterval('fireFireworks()', 5000);

When both of these are defined in my local file and not in the fireworks.js file I get a bad reference to createFirework().

So I moved the fireFireworks() to just under the initialize function in fireworks.js and then I would get a bad reference to fireFireworks() so I moved my setInterval into the intialize function, but I still get a bad reference to fireFireworks().

However, if I change the binder for onmouseup from
document.addEventListener(‘mouseup’, createFireworks, true);
to
document.addEventListener(‘mouseup’, fireFireworks, true);

It successfully creates my multiple fireworks.

I’m assuming that the scope of setInterval is playing a part here. If anyone could give me an idea of how I could automate this as well as some info as to why my setup isn’t working I’d really appreciate it!

  • 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-28T05:58:13+00:00Added an answer on May 28, 2026 at 5:58 am

    It’s nicer to pass the function itself to setInterval, i.e.

    setInterval (fireFireworks, 5000)
    

    As for the scoping, if your createFireworks function isn’t used anywhere else, just put it inside fireFireworks and you don’t have to worry about it any more (it’s generally considered nicer to do that anyway, because it avoids polluting the global scope).

    Otherwise, wrap both functions in a closure:

    (function ()
    {
        function fireFireworks ()
        {
            /* ... */
        }
    
        function createFirework ()
        {
            /* ... */
        }
    
        setInterval (fireFireworks, 5000)
    
    }) ();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.