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 JavaScript Foundations Functions Anonymous Functions

nicholas maddren
nicholas maddren
12,793 Points

Challenge Makes No Sense To Me

The coding doesn't seem to be the problem. It's what they are asking of me that is the problem. For example the challenge is:

Set the variable 'anonymousFunction' to be an anonymous function without any code to be executed.

So I this code:

var anonymousFunction = function() {});

It's an anonymous function isn't it?

Thanks

4 Answers

Nathaniel Miller
Nathaniel Miller
8,802 Points

If you haven't figured this out yet, maybe this will help:

http://markdalgleish.com/2011/03/self-executing-anonymous-functions/

As the article says in that link, "Those two little brackets cause everything contained in the preceding parentheses to be executed immediately."

So the answer is to add () to line 20, immediately before the ;

wow it was such a great article! I think I get it .

Aaron Graham
Aaron Graham
18,033 Points

It looks like you have an extra ")". Try this:

var anonymousFunction = function() {};

nicholas maddren
nicholas maddren
12,793 Points

Thanks so I managed the first task but now they want me to execute it. Here is my code:

var anonymousFunction = (function () { window.didExecute=true })();

For some reason it isn't passing. As I am dyslexic I'm having real hard time understanding what they want me to do. It would be great if they went a little more in-depth.

Aaron Graham
Aaron Graham
18,033 Points

I think they want you to execute it using the variable you assigned it to. Like this: anonymousFunction();

The way you have it written would execute the function and assign the return value to anonymousFunction. This can be very handy (if you are interested, try a google search for javascript closures), but with your current code, you are essentially just assigning anonymousFunction a value of "undefined".