HTML5 introduces more flexibility in how audio files are used on the Internet. In this recipe, we will create a game to practice loading and playing sounds using the audio tag and JavaScript.
You will need an audio file to play, an image, and a modern browser that supports HTML5. The example files for this chapter can be downloaded from http://www.packtpub.com/support?nid=7940. The Free Sound Project (http://freesound.org) has audio files you can use as long as credit is given to the producer, and photos can be found at http://www.Morguefile.com for use in your personal projects.
Now we are ready to create a series of buttons and a short JavaScript program that will play a random audio file when one of the buttons is pushed.
Open up your HTML editor and create the opening section of an HTML5 page.
<!DOCTYPE html><html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <...