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

Paul Utesch
Paul Utesch
2,927 Points

What is window. Nothing has mentioned anything about windows thus far. How do I create a window object?

I can't really get code to compile is I'm trying to reference an object that never existed.

2 Answers

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

In front-end Javascript, there is a global Window object simply called 'window.' It has a lot of properties like innerWidth, innerHeight, location, etc. You can read about it at the Mozilla Developer Network

I'm afraid that is the best I can do for you right now given that I don't know what you're trying to do, or what problem you're trying to solve. If you provide some more detail, perhaps I can help some more.

Paul Utesch
Paul Utesch
2,927 Points

The first question was to make the "anonymousFunction" complete. This is the second question: On about line 18, make the anonymous function with the code 'window.didExecute = true' execute:

  var anonymousFunction=function(){};

  (function () {
    window.didExecute = true;
  });

I have run multiple solutions with 'console.log' but when I put in the 'window.didExecute' line it tells me that window is undefined.

Nicholas Olsen
seal-mask
.a{fill-rule:evenodd;}techdegree
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Points

Anonymous functions are executed with a set of parenthesis at the end like this:

(function() {
    // Code to be executed;
})();

Notice the '()' at the end. Try completing the task they've given you with a set of parenthesis and see if that works. If not, then post all of the code you have and I can look over it.

Paul Utesch
Paul Utesch
2,927 Points

That worked. Thank you so much! I was going insane on that one.