Need help with javascript problem solving Exercices

function sumFirstN(n) {
    let sum = 0;

    if (n < 0) {
        sum = NaN;
    }
    else { 
        for (let i = 1; i <= n; i += 1) {
            sum+= 1;
        }
    }
    return sum;

    

I dont get why it gives the output that it gives,
For example, input= 5 output= 15.
I dont get the formula and the principles behind it.
Could anyone help please?

1 Like

It doesent make sense to me either the math aint mathing, still havent figured this out yet either.

2: 3
+1

3: 6
+3

4: 10

  • 6

5: 15

  • 10

6: 21

  • 15

7: 28

  • 21

where does this possibly make sense lol
its plus half input, 2 times input, 2 times input + half input, 3 times input, 3 times input plus half input…