Intro to the math formulas
Note
In the function editor, you can perform any JS method, using any value from cookies, variables, parameters, request responses, inputs or forms. Make sure to use the parameters correctly.
Math.abs()
Description Returns the absolute value of a number (removes negative sign if present). Useful for distance calculations or non-negative contexts.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const number = -7.25;
return Math.abs(number); // Result: 7.25 `
Math.round()
Description Rounds a number to the nearest integer. Perfect for simplifying decimal results (e.g., prices, ratings).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const price = 9.87;
return Math.round(price); // Result: 10 `
Math.ceil()
Description Rounds a number up to the nearest integer. Ideal for ensuring minimum capacity (e.g., seats, resources).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const users = 15.1;
return Math.ceil(users / 10); // Result: 2 (for 15.1/10 = 1.51 → rounded up) ```
Math.floor()
Description Rounds a number down to the nearest integer. Used for truncating decimals (e.g., age calculations).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const age = 29.9;
return Math.floor(age); // Result: 29
Math.max()
Description Returns the largest value from a list of numbers. Helpful for comparisons (e.g., finding highest scores).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
return Math.max(4, 12, 3, 9); // Result: 12
Math.min()
Description Returns the smallest value from a list of numbers. Useful for constraints (e.g., discounts, limits).
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
return Math.min(4, 12, 3, 9); // Result: 3
Math.random()
Description Generates a random decimal between 0 (inclusive) and 1 (exclusive). Combine with other methods for custom ranges.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
const randomNum = Math.random();
const diceRoll = Math.floor(randomNum * 6) + 1; // Result: Random integer between 1-6 `;
return diceRoll;
Math.pow()
Description Calculates the base raised to an exponent (baseexponent). Used for growth calculations or geometric operations.
/* Keep in mind that this example has fixed values, however,
you can replace any value with a value from a cookie, variable, form, input, etc. */
return Math.pow(2, 3); // Result: 8 (2³ = 2*2*2) ```