Assistant Upgrade explainer


#1

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, 'assistantFunctions', which would be the name of another file.

To turn off the fan, you call the myAssistant() function, and use a time (as a string) and the turnOffFan callback.

Sample code solution:
(Tap below to reveal)

import { recordShow, setAlarm, turnOffFan, turnOnFan, turnOffLight, turnOnLight } from 'assistantFunctions';

function myAssistant(time, callbackFunction) {
  console.log('Scheduling:');
  callbackFunction(time);
  console.log('Complete.');
}

myAssistant('8am', turnOnFan);
myAssistant('6pm', turnOffFan);

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