Light the firecracker!
Use JavaScript Event Listeners and Audio to click an image of a firecracker, change the image source, and play a sound!
To complete this project, students should have the following:
- Basic understanding of HTML structures and attributes.
- Basic understanding of JavaScript and DOM (Event Handling).
HTML | Description |
---|---|
audio | An audio element. |
JS | Description |
---|---|
Event Handler | A function invoked by an Event Listener. |
Event Listener | element.addEventListener('event', function(){}) listens for when the event has happened. If the event has happened (click, keydown...etc.), the function is executed. |
To complete Part I, fulfill the following requirements:
- Set up your project file structure through the command line.
- Create the following:
- HTML file
- CSS file
- JS file
- Link all of your files correctly.
To complete Part II, fulfill the following requirements:
- Create an
img
with anid
of "firecracker". Specify the correctsrc
to the firecracker.jpg image. - Create an
audio
with anid
of sound. Specify the correctsrc
to the explosion.png sound.
To complete Part III, fulfill the following requirements:
- Target the
id
of "firecracker".
- Make it so that the image is a little smaller. Hint: What properties can you use to change the size of an element?
TO complete Part IV, fulfill the following requirements:
- Create a
variable
called firecracker that will store the firecracker image. - Create a
variable
called sound that will store the audio element. - Add an
EventListener
to the firecracker image that listens for aclick
. When the image is clicked, do the following:
- Change the
src
of the firecracker image to the explosion.png. Make sure to specify the correct path to the explosion.png file. - Play the sound!
- Create 2 more firecrackers that will also show the explosion and play a sound on click!
Event Listeners: https://www.w3schools.com/js/js_htmldom_eventlistener.asp Get an Element By Id: https://www.w3schools.com/jsref/met_document_getelementbyid.asp