Create an Adder and a Exponentiation
In the world of programming languages, printing "Hello, World!" is a traditional starting point. In OOMOL, we will start by creating a simple adder and a power calculator.
Create an Adder


OOMOL Studio has some built-in system blocks, and scriptlet blocks are included, such as: Python, TypeScript, JavaScript.
As shown in the image above, we will drag the JavaScript scriptlet block from the toolbox on the right into the Flow.
We will write the code for the adder in this scriptlet block.
Configure Inputs


When you finish dragging, OOMOL Studio will create a basic scriptlet block, so we need to add some input definitions in this block to meet our needs.
Write Code
After you finish dragging, you will notice that there is already some code at the bottom of the block. This code is pre-generated by OOMOL Studio and includes type definitions for inputs and outputs and the entry function of the program.
//#region generated meta
/**
* @import { Context } from "@oomol/types/oocana";
* @typedef {{
* a: number;
* b: number;
* }} Inputs;
* @typedef {{
* output: any;
* }} Outputs;
*/
//#endregion
/**
* @param {Inputs} params
* @param {Context<Inputs, Outputs>} context
* @returns {Promise<Outputs>}
*/
export default async function (params, context) {
// your code
return { output: "output_value" };
}
We will focus only on lines 20-23 for now.
We will change it to the following code:
return { output: params.a + params.b };
Now our adder is complete. It will receive two numeric inputs a
and b
, and return their sum as output.
Execute


We will change parameter a
to 1
, change parameter b
to 2
, and then click the button in the upper right corner of the block to see the output result in the flow logs below.
Create a Exponentiation


Next, we will create a exponentiation that takes two inputs: one is the base and the other is the exponent, returning the base raised to the power of the exponent.
We can achieve this by copying the previous adder block and then modifying the input and output logic.
//#region generated meta
/**
* @import { Context } from "@oomol/types/oocana";
* @typedef {{
* base: number;
* exponent: number;
* }} Inputs;
* @typedef {{
* output: any;
* }} Outputs;
*/
//#endregion
/**
* @param {Inputs} params
* @param {Context<Inputs, Outputs>} context
* @returns {Promise<Outputs>}
*/
export default async function (params, context) {
return { output: Math.pow(params.base, params.exponent) };
}
Now our exponentiation is complete. It will receive two numeric inputs base
and exponent
, and return base
raised to the power of exponent
as output.