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

varis darasirikul
varis darasirikul
10,832 Points

Troubles with JavaScript Foundations,anonymous function Challenge task

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

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

9 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Thank you for the link. I understand what's going on now.

I added parentheses to the end of the anonymous function. This will cause the function to be executed.

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

  (function () {
    window.didExecute = true;
  })();
</script>
varis darasirikul
varis darasirikul
10,832 Points

Sorry for my late,i didn't come in to this site for many days. I don't sure you can get through this code challenge or not,but if you don't you can use this code below to pass it.

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

  (function () {
    window.didExecute = true;
  })();
</script>
Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Varis,

You want to place the code to be executed between the curly braces. So it would look like this.

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

If I understand your problem correctly, this would give you the desired result. I hope this helps.

varis darasirikul
varis darasirikul
10,832 Points

Hello Justin,

Thank you for your help but it doesn't work yet. Because Task 1 is about create anonymous function that is var anonymousFunction = function( ){ } ;

But task 2 is a problem. and this is comment

You're missing the parentheses at the end of the function '( function( ){ window.didExecute = true ;} )'

And I don't know how to add parentheses after that function.

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Sorry for my misunderstanding. Would you mind providing a link to the code challenge?

If the task is to create an anonymous function and then call it, I would expect the code to look something like this.

<script>
    var anonymousFunction = function() { window.didExecute = true };
    anonymousFunction();
</script>
varis darasirikul
varis darasirikul
10,832 Points

Thank again for your help but i try it and it doesn't work again. And this is a link to the code challenge. http://teamtreehouse.com/library/anonymous-functions

thank you.

Prabhakar Undurthi
Prabhakar Undurthi
4,846 Points

Hi , can you share me the code , I couldn't get through this code challenge.