I have this code - its a bit tricky:

```
let i = 0;
const inputBuffer = [];

const randomnumber = (min, max) => {
    return Math.floor(Math.random() * (max - min + 1) + min);
}

for (let k = 0; k < 10; k++) {
    console.log(convert(randomnumber(0, 1982)));
}

function convert(input) {
    inputBuffer.push(input);
    const output = {"current" : "0"};

    if (i % 3 == 0) {
        let sum = 0;
        for (let ii = 0; ii < i; ii++) {
            sum += inputBuffer[ii];
        }
        output.sum = sum;
    }
    i++;
    output.current = input;

    return JSON.stringify(output);
}

```

The output looks like this:

```
{"current":605,"sum":0}
{"current":708}
{"current":456}
{"current":1838,"sum":1769}
{"current":1619}
{"current":1404}
{"current":1068,"sum":6630}
{"current":1178}
{"current":989}
{"current":1280,"sum":9865}

```

But I want it to look like this:

```
{"current": 605}
{"current": 708}
{"current": 456}
{"current": 1838,"sum":1769}
{"current": 1619}
{"current": 1404}
{"current": 1068,"sum":6630}
{"current": 1178}
{"current": 989}
{"current": 1280,"sum":9865}

```

```js
let i = 0;
const inputBuffer = [];

const randomnumber = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1) + min);

}
for (let k = 0; k < 10; k++) {
  console.log(convert(randomnumber(0, 1982)));
}

function convert(input) {
  inputBuffer.push(input);
  const output = {
    "current": "0"
  };
  if (i % 3 == 0) {
    let sum = 0;
    for (let ii = 0; ii < i; ii++) {
      sum += inputBuffer[ii];
    }
    output.sum = sum;
  }
  i++;
  output.current = input;

  return JSON.stringify(output);
}
```

I don't want to show the sum the first time but later show it every 3 times

Got any ideas? :D

PS. I prefer staying basic and only use a for loop

Have a nice evening