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

Jason Larkin
Jason Larkin
13,970 Points

Anonymous Function Problem

The code challenge calls for making the anonymous function variable not execute in the first challenge, but wants you to make it execute in the second. Can anybody please help?

<script>
      var anonymousFunction = function () {};

      (function () { return 
        window.didExecute = true;
      });
    </script>

3 Answers

Hi Jason,

The 1st line of code is for task 1 only and doesn't have anything to do with task 2.

The code of interest for task 2 is the following:

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

So the challenge wants you to make that anonymous function execute. The way you make a function execute is by adding parentheses at the end right before the semi-colon.

Jason Larkin
Jason Larkin
13,970 Points

Thanks Jason. I was on the verge of figuring it out, but you helped immensely.

Hi lata,

If you put them right before the semi-colon then it should work.

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

Post the code that you're trying if it's still not working for you.

Glad you figured it out!

Daniel Quaidoo
Daniel Quaidoo
23,937 Points

You're calling the anonymous function wrongly. Review the video.

Jason Larkin
Jason Larkin
13,970 Points

I've watched it seven times and I still don't see it.