simpleFunction
The recommended way to perform calculations in CL is to create a function that performs the desired operations, then evaluate it at the values you want to use. Here’s how:
Step 1: Create a function.
- Use simpleFunction to create the expression you’d like to use for calculating. For example, simpleFunction(`x+3`) takes the input and adds 3 to it.
- If you want to use multiple variables, list them out after your expression separated by commas:
simpleFunction(`x+y`,`x`,`y`) calculates the sum of x and y.
Step 2: Evaluate your function at the desired values.
- Once your function is created, evaluate it at the values you want using evaluateAt.
simpleFunction(`x+y`,`x`,`y`).evaluateAt(5,3) evaluates to 8.
simpleFunction(`x+3`).evaluateAt(input.numericValue) adds 3 to whatever value is entered into a math input.
In addition to evaluating numeric values without first converting to strings, simpleFunction is especially useful when you want to perform the same operation over and over again. As stated previously, simpleFunction is the recommended method for performing variable computations in CL. This is because of its reliability and durability. Give these features a try with these two screens!