> For the complete documentation index, see [llms.txt](https://scenegroup.gitbook.io/cavalry/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scenegroup.gitbook.io/cavalry/nodes/utilities/js-math.md).

# JS Math

Use JavaScript to perform mathematical operations on values.

**Expression** - an area to input mathematical operations/JavaScript expressions.

**Result** - a read only attribute previewing the result of the **Expression**.

**Add** - use this button to add more indices to the UI.

**0: Number** - the first index in the array

{% hint style="info" %}
To reference a row in your expression use the syntax `n[index number]`. For example, to reference the index labelled **0: Number** use the syntax **n0**.

Any strings with `n` followed by a `value` will be coloured to help visually identify them within an expression.
{% endhint %}

{% hint style="success" %}
**Example** - adding the values of two attributes together.

1. Create 3 Shapes.
2. Create a **JS Math** Atom.
3. Connect ***basicShape1.position.x*** > ***jsmath.number0***
4. Connect ***basicShape2.position.x*** > ***jsmath.number1***
5. Enter `n0 + n1` into the **Expression** input.
6. Connect ***jsmath.id*** > ***basicShape3.position.x** to output the result.*
   {% endhint %}

{% hint style="success" %}
**Example** - move one shape in X at a value of $$\sqrt{ofAnotherShape}$$&#x20;

1. Create 2 Shapes.
2. Create a JS Math Atom.
3. Connect ***basicShape1.position.x*** > ***jsmath.number0***
4. Enter `Math.sqrt(n0)` into the **Expression** input.
5. Connect ***jsmath.id*** > ***basicShape2.position.x***
   {% endhint %}

{% hint style="info" %}
See <https://htmlcheatsheet.com/js/#> for some JavaScript syntax.
{% endhint %}

{% hint style="info" %}
To remove indices from the array, select a row or rows, right click and choose **Delete Selected Attribute(s)**.
{% endhint %}
