Dinner Date explainer

Aim of the puzzle: Use a function that takes a callback function as an argument.
Walk through of solution: In this puzzle, there are 3 functions declared: orderGroceries(), orderPizza(), and scheduleDinner().

orderGroceries() and orderPizza() are simple functions that print a message to the console using console.log().

The last one, scheduleDinner(), is special. It takes both a string (day) and a function (mealFunction) as an argument. When a function is used as an argument, it is called a callback function. Using a callback function makes scheduleDinner() more flexible, as it can run either orderGroceries or orderPizza, depending on which one it takes as a callback.

Below the function declarations, scheduleDinner('Monday', orderPizza) calls the scheduleDinner() function with 'Monday' as day and orderPizza as the callback mealFunction.

To complete the puzzle, call scheduleDinner() again. Give it a day of the week (as a string) for the first argument, and then either orderPizza or orderGroceries as a callback.

Sample code solution:

function orderGroceries(day) {
  console.log('Groceries will be ordered on ' + day);

function orderPizza(day) {
  console.log('Pizza will be ordered on ' + day);

function scheduleDinner(day, mealFunction) {
  console.log('Scheduling dinner...');

scheduleDinner('Monday', orderPizza);
scheduleDinner('Tuesday', orderGroceries);

Javascript Concepts: Functions, Callback Functions, Strings, console.log()


The answer is right, but the code appears to ask more and I don’t know what to do…


Hi, there’s a bug that makes the orderGroceries callback not complete the puzzle. This will be fixed in the next update. For now, you should be able to pass the puzzle if you only use orderPizza.



We are calling back ‘MealFunction’ but we it hasn’t been defined yet?


I dont get why this is executed in that order. the computer starts reading from tob to bottom right?


What’s the purpose of MealFunction in this code, can anybody explain?