Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Treehouse Club: JavaScript Car Sounds How to Get an Image Respectfully

How can I add a sound to the image within the body section?

I would like to add a sound of the body section. How can I do that and how does the code look like?

^^^ <body> <!--Car image --> <img src="images/porsche.png" class="car" alt="car"> ^^^

2 Answers

Hi Simon

There is an element called "audio" that you can add your sound files too.

In the body element you would have an image, as well as a audio source with it, that could look something like this:

<body>
    <div class="car">
        <img src="images/porsche.png" class="car__image" alt="car" />
        <audio class="car__audio" controls>
            <source src="car.mp3" type="audio/mp3">
            <source src="car.ogg" type="audio/ogg">
            <p>Your browser doesn't support HTML5 audio. Here is a <a href="car.mp3">link to the audio</a> instead.</p>
          </audio>
    </div>
</body>

check out this TreeHouse video on audio and video

Further reading

Good Luck

Thank you so much