Example for Create a JavaScript Module

This example demonstrates the creation of the factorial_mod JavaScript module.

  1. In the Connections panel, click the + icon in the JavaScript Modules node and then click Create.

  2. In the MLE Module Name field, enter factorial_mod.

  3. Click Apply.

    The module appears under JavaScript Modules in the Connections panel.

  4. In the Connections panel, expand JavaScript Modules, right-click factorial_mod and select Open.

    The factorial_mod module pane appears.

  5. Enter the following JavaScript function:

    export function factorial(num) {
        if(num < 0) {
    
            return -1;
        } else if (num == 0) {
    
            return 1;
        } else {
            return(num * factorial(num-1));
        }
    }
  6. Click the Compile icon to save the JavaScript code.

    Note: Alternatively, you can save the code by using ctr + s or cmd + s.

To import a module to an MLE environment, see Example for Create an MLE Environment.