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

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 ;