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

Nazaam Kutisha
Nazaam Kutisha
7,667 Points

Challenge question #2

Question: On about line 18, make the anonymous function with the code 'window.didExecute = true' execute.

My response:

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



    </script> ```

2 Answers

Hi Nazaam,

The code from task1 and 2 are two separate things and it looks like you've tried to combine them.

Task1 code would have been var anonymousFunction = function() {}; An anonymous function that doesn't do anything has been assigned to the variable anonymousFunction

Separately they want you to execute the anonymous function that begins on line 18. To do that you add parentheses at the end of it.

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

This is an immediately-invoked function expression

Nazaam Kutisha
Nazaam Kutisha
7,667 Points

Hi Jason,

I tried it this way first, I must of had too few parentheses.

Many Thanks,