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 HTML Comments and JavaScript

Chandelor Simon
Chandelor Simon
2,242 Points

Why don't I have to change 'startCar' to 'startCarA' in all fields: buttons, audio files, and Javascript?

I was playing around with the html; when I went to change:

<audio id="startCar" src="sounds/startCar.wav" preload="auto"></audio>

to instead reflect:

<audio id="startCar" src="sounds/startCarA.wav" preload="auto"></audio>

I thought I would need to change the code in Buttons and Javascript to reflect the change, as well:

<!--for Buttons--> <a href="javascript:startCarA();"><img src="images/key.png" alt="key"></a>

<!--and for Javascript--> function startCarA() { document.getElementById('startCarA').play();

When I added those changes in altogether and refreshed the page - there was no longer audio when I clicked the key. As I continued to play I found that when I only edited the audio to 'startCarA'- leaving the buttons and Javascript unaltered - it played the different sound.

I recall Joy saying you have to make changes to everything because all the pieces work together; would someone kindly clarify what's different about this aspect?

1 Answer

Steven Parker
Steven Parker
229,670 Points

I can see how that might be a bit confusing! That comment about changing things together would apply to identifiers like variable names. The name itself is not important, but you must be careful to use it consistently throughout the program.

In this case, the change is not being made to a program identifier, but to a file name. The file name is only used once in the program, as the value for the "src" attribute of the "audio" element. The file name might happen to look similar to a function name in the program, but they really are not related.

Chandelor Simon
Chandelor Simon
2,242 Points

Thank you, Steven - I understand now! It's not changing the file name, just the thing we're using (CarA). Muchas gracias, my man!