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 trialvaris darasirikul
10,832 PointsTroubles 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
Treehouse Guest TeacherThank 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
10,832 PointsSorry 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
Treehouse Guest TeacherHello 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
10,832 PointsHello 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
Treehouse Guest TeacherSorry 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
10,832 PointsThank 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.
varis darasirikul
10,832 Pointsoh it work!
thank you so much.
Justin Horner
Treehouse Guest TeacherYou're welcome! Glad I could help.
Prabhakar Undurthi
4,846 PointsHi , can you share me the code , I couldn't get through this code challenge.