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 trialValerie Laughlin
Front End Web Development Techdegree Graduate 16,110 PointsIn the app.js file, functionRunner executes a callback, log. Convert log in to an anonymous function and pass the anonym
I am really stuck on this javascript question that seems to have a simple answer.
The exercise is telling me to convert "log" into an anonymous function which I believe is :
function log() {
}
Then I get error messages saying that callback still has a name
I am also confused with how to pass the anonymous function directly to functionRunner
Is it?
function () { functionRunner.log("Hello World!"); }
Thank you for your help
function log() {
console.log("Hello World!");
}
functionRunner(log);
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel='stylesheet' href='styles.css'>
</head>
<body>
<section>
<p>Open your browser's console to see the results</p>
</section>
<script src='runner.js'></script>
<script src='app.js'></script>
</body>
</html>
function functionRunner(callback) {
callback();
}
Valerie Laughlin
Front End Web Development Techdegree Graduate 16,110 PointsThank you so much!
8 Answers
jacknoren
24,134 PointsFor everyone still having problems with this - just copy and paste my code into the section.
function log() {
console.log("Hello World!");
}
functionRunner( () => {
console.log("Hello World!");
});
Anna Oleszczuk
6,010 Pointsthat works + you can remove the curl braces because you don't need them here.
Josh Morden
Full Stack JavaScript Techdegree Student 551 Pointsthis challenge is bugged.
function log() { console.log("Hello World!"); }
// I convert the above function into an anonymous function and pass it as a parameter.
functionRunner(function () { console.log("Hello World!"); });
Yet it is still flagged as incorrect.
Josh Morden
Full Stack JavaScript Techdegree Student 551 PointsI found the issue. To pass this task, you need to delete the original, named, function after converting it to an anonymous function and passing it as a parameter. The challenge only asks you to convert the function into an anonymous function and pass it as a parameter, hence the confusion.
Amelia Bosley
11,700 PointsI can't get this to work either. Either with my own code or with the previous answerer's code.
Souleymane Diop
Front End Web Development Techdegree Graduate 16,712 PointsTry this perhaps
functionRunner(() => console.log("Hello World!"));
Nurgul Amat
Front End Web Development Techdegree Graduate 21,456 PointsfunctionRunner(function() { console.log("Hello World!"); });
Max van den Berge
6,506 PointsIt still doesn't work Andrew Chalkley
function functionRunner(callback) { callback(); }
functionRunner(() => console.log("Hello World!"));
Bummer: The callback still has a name!
JQMIGRATE: Migrate is installed with logging active, version 1.4.1 head_vendor-5b9ebdc4a02e1b2e5ee764c861e9bbb31c76ac261c1825fea64a849cc73d8085.js:1185 [bugsnag] Ignoring cross-domain or eval script error. See docs: https://tinyurl.com/y94fq5zm t @ head_vendor-5b9ebdc4a02e1b2e5ee764c861e9bbb31c76ac261c1825fea64a849cc73d8085.js:1185 d3cxv97fi8q177.cloud…58b85e71.min.js:392 Uncaught SyntaxError: Unexpected end of input head_vendor-5b9ebdc4a02e1b2e5ee764c861e9bbb31c76ac261c1825fea64a849cc73d8085.js:1185 [bugsnag] Ignoring cross-domain or eval script error. See docs: https://tinyurl.com/y94fq5zm t @ head_vendor-5b9ebdc4a02e1b2e5ee764c861e9bbb31c76ac261c1825fea64a849cc73d8085.js:1185 d3cxv97fi8q177.cloud…58b85e71.min.js:392 Uncaught SyntaxError:
Unexpected end of input app.js:7 Hello World!
gennady
14,145 Pointsgennady
14,145 PointsHi, Valerie! An anonymous function looks like:
function() {}
So, as you can see "anonymous" means no name like "log". So, your anonymous function will look like:
function() {console.log("Hello World!");}
And the same function pased to the runner will look like: