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
Aaron Chiandet
9,826 PointsAnonymous Function Code Challenge has me stumped
I recently began learning JavaScript and it's been much more challenging than anticipated. I think I might be moving through the deep dive too fast because I'm stuck on something that should be simple. I've re-watched the anonymous variable video multiple times now and I can't figure this out. I'm assuming this is a fundamental mistake that I'm overlooking from a previous video. Please assist...
Question: On about line 18, make the anonymous function with the code 'window.didExecute = true' execute.
My Code:
<script>
var anonymousFunction = function() {
};
anonymousFunction (function() {
window.didExecute = true;
})();
</script>
It's returning this hint, "Was expecting window.didExecute to be true was undefined."
This is why I assume its a silly fundamental mistake, I don't know why it's returning undefined?
4 Answers
Aaron Chiandet
9,826 PointsI completely started over and I figured it out, so silly when I realized what I was doing wrong. Sometimes it hurts to spend too much time working on this stuff. More breaks are needed.
<script>
var anonymousFunction = function() {
};
(function() {
window.didExecute = true;
})();
</script>
Chris Ellinger
26,494 PointsI think thats my problem as well. I've been burning through this course and I need a break.
iaan van niekerk
5,520 Pointsvar anonymousFunction = function(){};
(function () {
window.didExecute = true;
})();
I got the answer here, you have to remove the empty variable in step two. Because it's from the global.
Aaron Chiandet
9,826 PointsMy gut is telling me I'm missing a variable but I don't know where to begin?
Matt Campbell
9,767 PointsWhat's with the variable declaring an empty function? It's not doing anything.
Tony Nguyen
24,934 PointsThat's because the first task was to name the anonymousFunction to a anonymous name function.
Richard Glover
10,068 PointsRichard Glover
10,068 PointsThe question is wrong. It asks to input on line 18!! That is where I am getting confused because of the questions and not my complete lack of understanding. I was thinking on the lines of your correct answer in your next post but as the question suggested that we need to input on line 18 I thought I must be wrong. I again had to search for an answer and thanks to Aaron I have the answer without waiting a few hours for someone to get back to me with help.