Drinks and Desserts explainer

The aim of this puzzle: Use an imported function as a callback.

Walkthrough of the solution: The solution to this puzzle is similar to the previous ones. The only difference is that the callbacks aren’t declared in code, but they aren’t entirely in hidden code either. The 1st line is an import statement. An import can access data or functions from another location. In this case, orderFunctions, which would be the name of another file.

To order desserts, you call the scheduleDinner() function, and use a day (as a string) and the orderDesserts callback.

Sample code solution:
(Tap below to reveal)

import { orderGroceries, orderPizza,  orderDesserts, orderDrinks} from 'orderFunctions';

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

scheduleDinner('Friday', orderDrinks);
scheduleDinner('Saturday', orderDesserts);

JavaScript Concepts: Functions, Callback Functions, Strings, console.log()
Additional Code (hidden code that runs before the puzzle’s code):

const orderGroceries =day => {
   console.log(`Groceries will be delivered on ${day}.`);
};

const orderPizza = day => {
   console.log(`Pizza will be delivered on ${day}.`);
};

let orderDesserts = day => {
  console.log(`Desserts will be delivered on ${day}.`);
};

let orderDrinks = day => {
   console.log(`Drinks will be delivered on ${day}.`),
};
3 Likes