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!

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

How to solve challenge 2?

I need some help with this challenge. I put parentheses at the end of the anonymous function and set a variable inside of the function. it was wrong and said: Was expecting window.didExecute to be true was true

don't know what that means.. any help?

James Barnett
James Barnett
39,199 Points

It's hard for us to know what's causing the issue you are having if you don't show us your code. For some tips on how to do that, check out the tips for asking questions video located in the right hand sidebar.

So if you still need more help after reading Dino Paškvan's advice, post what code you've got so far.

1 Answer

They're basically asking you to turn the already written function into something called an IIFE (Immediately-Invoked Function Expression).

You can't invoke an anonymous function later on unless you assign it to a variable. The only thing you can do with them is invoke them immediately, and you do that the same way you would with any other function — by adding () after it.

(function () {
  // code that does something
})(); // note the parentheses that invoke the function

Also, that's all you're supposed to do in this task, you're not supposed to add any variables or change the anonymous function, just make it execute.