# JavaScript examples

These examples use the [Investment Growth Calculator](https://www.equalto.com/suresheet/view/abc7cbef-2491-4787-94f8-6542fab12a4e) SureSheet.

### Simple example

```javascript
(async () => {
    const workbookId = "abc7cbef-2491-4787-94f8-6542fab12a4e";
    const simulateUrl = `https://www.equalto.com/suresheet/api/v1/simulate/${workbookId}`;
    const response = await fetch(simulateUrl, {
        method: 'POST',
        body: JSON.stringify({
            inputs: {
                Sheet1: {
                    C6: 25000,
                },
            },
            outputs: {
              Sheet1: ['C13'],
            },
        }),
        headers: {
            'Content-Type': 'application/json',
        },
    });
    const responseJson = await response.json();
    console.log(responseJson)
})();
```

Should print:

```json
{'Sheet1': {'C13': 50783.31719489607}}
```

### Advanced example with ranges

```javascript
(async () => {
    const workbookId = "abc7cbef-2491-4787-94f8-6542fab12a4e";
    const simulateUrl = `https://www.equalto.com/suresheet/api/v1/simulate/${workbookId}`;
    const response = await fetch(simulateUrl, {
        method: 'POST',
        body: JSON.stringify({
            inputs: {
                Sheet1: {
                    C6: 25000,
                },
            },
            outputs: {
              Sheet1: ['C13', 'B14:C16'],
            },
        }),
        headers: {
            'Content-Type': 'application/json',
        },
    });
    const responseJson = await response.json();
    console.log(responseJson)
})();
```

Should print:

```json
{
    "Sheet1": {
        "C13": 50783.31719489607,
        "B14:C16": [
            [
                "   Initial investment amount:",
                25000.0
            ],
            [
                "   Additional contributions:",
                10500.0
            ],
            [
                "   Interest earned:",
                15283.31719489607
            ]
        ]
    }
}
```
