Skip to main content

Functions

Functions are generally a JavaScript topic and more can be found through various tutorials on JavaScript and such.

Create a Function

To create your own function in hlab.app, simple type {function_name}({parameter1}, {parameter2}, ... ) { {code_text} }

As an example, let's create a function that adds 2 and divides by 3. We need a precise name, and use lower case, preferably with underscore notation like this: my_name_is_this.

We'll go with the name oper1 for operation1. Since this will help us remember it's an operation and we can reference it numerically if it grows large enough.

    //code goes here..
}

Now let's write the logic of it, that is the add 2 divide by 3 part (and return the value):

    let val = (input + 2)/3;
return val;
}

OR

    return ((input + 2)/3)
}

Functions are the main driver of code. You write functions so you can reuse code blocks, or use them with variations through parameters or input changes. They're very important, and if you need a grasp of them, we highly recommend reading the MDN documents: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions