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

What is the answer to this question and what is the rationale for this question?

return cb();

1 Answer

Hi Hanwen!

cb is the callback function that is passed into the makemeal function as a parameter.

Having passed it in, it would make sense to then execute it at some point inside the execution of makemeal (otherwise, what's the point of passing it in?!?).

So for this:

function makeMeal(meal, cb) {
  alert(`Preparing ${meal}.`);
  cb(); // YOU WANT TO CALL the cb funtion to execute it. (However, there's no need to return it, you're just running it.)

makeMeal('lunch', () => { // This is cb passed in as an anonymous function argument
  alert('Finished the meal!');

I hope that helps.

Stay safe and happy coding!

Thank you Peter!!