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

8,265 Points

Stuck on JavaScript Anonymous Function second part, please help me understand the problem.

The challenge is: make the anonymous function with the code 'window.didExecute = true' execute.

My current code is this: which does not pass.

      var anonymousFunction = function () {

2 Answers

In the second task, you need to concentrate on this part of the code:

(function () {
    window.didExecute = true;

Your task is to create what is known as IIFE (immediately-invoked function expression).

This code is a function, but because it's an anonymous one, you can't execute it by calling its name, and it won't get executed on its own. However, it's still a function and same rules apply. To call a function, you'd add the parentheses after its name.

So, all you're supposed to do is add () before the final semicolon.

8,265 Points

Dino - thank you so much for explaining it to me, it helped alot,