Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Andrew Chappell
Andrew Chappell
12,782 Points

How to Set the variable 'anonymousFunction' to be an anonymous function without any code to be executed.

Hi people, I can't do this anonymous function challenge. It says "The 'anonymousFunction' is not a function!"

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>JavaScript Foundations: Functions</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Functions: Anonymous Functions</h2>
    <script>
      var anonymousFunction = function() {
        return;
      }


      (function () {
        window.didExecute = true;
      });
    </script>
  </body>
</html>

2 Answers

Andrew Chappell
Andrew Chappell
12,782 Points

This code worked! Fixed.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>JavaScript Foundations: Functions</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Functions: Anonymous Functions</h2>
    <script>
      var anonymousFunction = function () {
      };

      (function () {
        window.didExecute = true;
      });
    </script>
  </body>
</html>

You need () before your ;

Above </script>

Above < / script >

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

Are they trying to throw you off saying it's around line 18 because I find it more like instructions to write the code on like 18.

Is there a way to answer the question by typing code on line 18 or is simply just adding that () before ;