3

Super beginner here, I read the similar questions asked here and it did not solve my problem.

I know the instructions say that I'm only supposed to amend the final line (var burger...), but I cannot get this one to pass.

var food = function() {
  return function() {
    return "HAMBURGER"
  }
}

var burger = food();

I want to return "HAMBURGER" but instead I return [Function]

Turnip
  • 35,836
  • 15
  • 89
  • 111
jsc42
  • 117
  • 9
  • 3
    try `food()()` - your function returns a function, so you need to invoke them both – Robbie Feb 08 '17 at 23:24
  • Why do you use a closure? You don't need one here. See http://stackoverflow.com/questions/111102/how-do-javascript-closures-work – Ram Feb 08 '17 at 23:25
  • You are already know how to call a function (`f()`). You know that calling `food` *returns a function*.... btw, what changes have you made to the last line so far? – Felix Kling Feb 08 '17 at 23:26

2 Answers2

3

As the function food returns an anonymous function, it has to be invoke to run and produce some result:

var food = function() {
  return function() {
    return "HAMBURGER"
  }
}

var burger = food()(); // or food().call()
console.log(burger)

An interesting article about different ways of function invocation could be found here.

MaxZoom
  • 7,619
  • 5
  • 28
  • 44
3

The simplest thing you can do if you are only supposed to change the bottom line is to change it to:

var burger = food()();

Which is the equivalent of:

var burgerFunction = food();
var burger = burgerFunction();

Your function returns a function, so you need to invoke them both

Robbie
  • 18,750
  • 4
  • 41
  • 45