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 trialNazaam Kutisha
7,667 PointsHelp with this challenge
Set the variable 'anonymousFunction' to be an anonymous function without any code to be executed.
my response isn't working here.
<script>
var anonymousFunction = function(); {
anonymousFunction();
};
</script>
4 Answers
Matthew Ludwigs
11,197 PointsThanks Dave, I should add the semicolon at the end of the function curl braces. The semicolon I was talking about was after the anonymous function like so:
var anonymousFunction = function(); {
At least when I tried to run the code this way I received a syntax error, but maybe I had another error in the code the created that issue. I was trying to recreate the problem in my environment, so I could help answer the question.
Matthew Ludwigs
11,197 PointsI do not believe you have to call the function inside of itself. Also, after the function() you have a semi-colon which will lead to a syntax error. If you delete the function call inside the curly braces and the semi-colon it should work. For example:
var anonymousFunction = function() {
}
This should work because now the variable is set to that anonymous function, and that function now does nothing.
Dave McFarland
Treehouse TeacherHi Matthew,
Excellent answer. You should add a semicolon at the end of the statement:
var anonymousFunction = function () {
};
You won't get a syntax error without the semicolon, but it's technically correct. Because you are assigning a value to a variable you're creating a JavaScript statement and it should end with a semicolon, just like any JS statement:
var a = "apple";
Nazaam Kutisha
7,667 PointsThis worked for the challenge
var anonymousFunction = function() { };
Great Responses..
Matthew Ludwigs
11,197 PointsI am glad we could help Nazaam!
Dave McFarland
Treehouse TeacherDave McFarland
Treehouse TeacherYeah, definitely. That IS a syntax error.