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

Callback Functions in Javascript Challenge. Can't get it right.

So, this is the exercise:

"In the app.js file, functionRunner executes a callback, log. Convert log in to an anonymous function and pass the anonymous function directly into functionRunner."

The pre-populated code is: function log() {

console.log("Hello World!"); }

functionRunner(log);

I have tried everything and cannot find a solution. Can someone help?

1 Answer

kevin curtis
kevin curtis
15,287 Points

Hi Amelia, So I'm thinking step one, let's convert the log function into an anonymous function:

function(){
    console.log("Hello World!"); 
 }

Step two, rewrite that code so your new anonymous function is passed into the functionRunner function:

functionRunner(function(){
    console.log("Hello World!"); 
 });

or written with a newer syntax:

functionRunner(() => {
    console.log("Hello World!"); 
 });