Assistant Upgrade 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, '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) {

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

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

const recordShow = time =>{
   console.log('Your show will be recorded at ' + time);

const setAlarm = time =>{
 console.log('Your alarm has been set for ' + time);

const turnOffFan = time => {
   console.log('Your fan will be turned off at ' + time);

const turnOnFan = time => {
   console.log('Your fan will be turned on at ' + time);

const turnOffLight = time => {
 console.log('Your lights will be turned off at ' + time);

const turnOnLight = time => {
   console.log('Your lights will be turned on at ' + time);

The import statement how does it know the location of the file, is it in the same directory ?

1 Like

The imported code is in additional code. It looks like this:

    recordShow: time => console.log('Your show will be recorded at ' + time),
    setAlarm: time => console.log('Your alarm has been set for ' + time),
    turnOffFan: time => console.log('Your fan will be turned off at ' + time),
    turnOnFan: time => console.log('Your fan will be turned on at ' + time),
    turnOffLight: time => console.log('Your lights will be turned off at ' + time),
    turnOnLight: time => console.log('Your lights will be turned on at ' + time),

Some of the syntax might look unfamiliar, but these are all functions that take a parameter named time, and return a console.log statement that includes a sentence followed by the given time.

Hope this helps!



No questions or complaints here, just a friendly suggestion.

Short Version:

  1. Name the link to the explanation after each exercise something other than “support forum”. Something more like “Breakdown” instead. Not suggesting removing the forum, just restructuring the appearance and flow and access to these things.

  2. Possibly even provide these breakdowns after each exercise as an element that users will definitely be aware of, perhaps an optional assignment they must at least click on to skip.

Long Version:

I was doing ok until a few exercises ago when I had to stop and read something repeatedly. Reading it repeatedly only helped me to identify why I didn’t understand. Being unaware of the hidden functions left holes in my reasoning. I assumed numbers were randomly produced but it was seeing an array of words that was the proverbial straw that sent me searching for an answer. I didn’t see a link to the information I needed anywhere, but I went poking around and thought someone might have asked a question in the “forum” that might help. It was a little confusing when the forum link led not directly to a forum, but first to the detailed explanations including the hidden code that I needed to know about all along. I understand that the hidden code allows simplicity needed to help ease beginners into understanding increasingly complex concepts and that it might be info overload for some at first, but it might be helpful to run through everything that’s currently in the beginning of these “forum” pages after each exercise is completed. There have been a few summary pages after assignments, but after reading them I was still missing information I needed. I’ve read a few forum posts from people stating that they’ve been filling in the blank with answers they’re given without learning anything at all. This reminded me of an experience I had in high school. I understood everything up until we were just having formulas thrown at us to memorize. I went from straight A’s to losing confidence. Searching for alternative texts to learn from on my own, I found one that walked through each logical progression that led to the formulas instead of just being given them and told to remember. It was all easy after that. I’ve had college professors who even refused to walk through proofs.
Assuming that the average person will be able to fill those gaps using the information we’re given in the instructions and deduction is maybe an overestimation in one area of ability. I haven’t messed with this stuff since I was figuring out MySpace hacks. Other than this one issue, everything has been very simple to use and very helpful.
Thank you for reading my input if you are still doing so. I really do enjoy Grasshopper and consider it my favorite new hobby. Thank you for helping people learn something that is becoming more useful every day. :slight_smile:


Hey there, thanks for taking the time to provide feedback. You have some great suggestions.

At Grasshopper we’re always striving to teach difficult concepts in a way that is beginner-friendly but not “dumbed down”. I’ve had those same experiences in my own coding education where I quickly went from feeling like I understood to feeling pretty overwhelmed.

We’re always open to user feedback on how to better provide a learning environment, so thanks again for taking the time. It helps make Grasshopper a better product for everyone.



For me, the function calls at the end feel similar to something like myAssistant( ‘hello’, print) giving print(hello). Only in this case entities like ‘print’ have already been created and imported ready for us to use in the function, just like we do with ‘print’.

another lesson where the hidden code only allows us to learn what and not why. It’s becoming apparent that this app wasn’t intended for people new to programming, just new to javascript

1 Like

I will execute your code that you put above and import from it, but this code does not execute and gives an error (node: 3848) Warning: To load an ES module, set “type”, where and how to execute this code To do?

Shouldn’t this be the hidden code?
The other one (with the constants) doesn’t run.

that is the imported code but how does the import function know where to import from? would assistantFunctions be located in another JavaScript file in the same directory? or is it more about collating earlier functions in the same JavaScript file/code?

if you use import function in your own code do you need an argument that is the location of another JavaScript file?

import(file2.js, function1, function2)