Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Callback Functions Review

Pass addEventListener() a reference to the handleChange function.

Why this one is incorrect T^T

1 Answer

Hi Hanwen!

When they say "pass a reference to the function", that just means the name of the function.

For example: playSound would be how you type that function as a passed-in parameter (meaning you leave the parens off, because you're not calling/running it yet).

When you then run it in the body of the function it was passed into, however, you'd use playSound();

Therefore the answer is:

function handleChange() {
  console.log('I was changed!');

select.addEventListener('change', handleChange); // Passed in only so far, and will run/execute only when select changes

I hope that helps.

Stay safe and happy coding!

Understood now, thank you